wp/wp-includes/js/dist/escape-html.js
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    80 /******/ 	// __webpack_public_path__
    80 /******/ 	// __webpack_public_path__
    81 /******/ 	__webpack_require__.p = "";
    81 /******/ 	__webpack_require__.p = "";
    82 /******/
    82 /******/
    83 /******/
    83 /******/
    84 /******/ 	// Load entry module and return exports
    84 /******/ 	// Load entry module and return exports
    85 /******/ 	return __webpack_require__(__webpack_require__.s = 381);
    85 /******/ 	return __webpack_require__(__webpack_require__.s = 465);
    86 /******/ })
    86 /******/ })
    87 /************************************************************************/
    87 /************************************************************************/
    88 /******/ ({
    88 /******/ ({
    89 
    89 
    90 /***/ 381:
    90 /***/ 465:
    91 /***/ (function(module, __webpack_exports__, __webpack_require__) {
    91 /***/ (function(module, __webpack_exports__, __webpack_require__) {
    92 
    92 
    93 "use strict";
    93 "use strict";
       
    94 // ESM COMPAT FLAG
    94 __webpack_require__.r(__webpack_exports__);
    95 __webpack_require__.r(__webpack_exports__);
       
    96 
       
    97 // EXPORTS
       
    98 __webpack_require__.d(__webpack_exports__, "escapeAmpersand", function() { return /* binding */ escapeAmpersand; });
       
    99 __webpack_require__.d(__webpack_exports__, "escapeQuotationMark", function() { return /* binding */ escapeQuotationMark; });
       
   100 __webpack_require__.d(__webpack_exports__, "escapeLessThan", function() { return /* binding */ escapeLessThan; });
       
   101 __webpack_require__.d(__webpack_exports__, "escapeAttribute", function() { return /* binding */ escapeAttribute; });
       
   102 __webpack_require__.d(__webpack_exports__, "escapeHTML", function() { return /* binding */ escapeHTML; });
       
   103 __webpack_require__.d(__webpack_exports__, "escapeEditableHTML", function() { return /* binding */ escapeEditableHTML; });
       
   104 __webpack_require__.d(__webpack_exports__, "isValidAttributeName", function() { return /* binding */ isValidAttributeName; });
    95 
   105 
    96 // CONCATENATED MODULE: ./node_modules/@wordpress/escape-html/build-module/escape-greater.js
   106 // CONCATENATED MODULE: ./node_modules/@wordpress/escape-html/build-module/escape-greater.js
    97 /**
   107 /**
    98  * Returns a string with greater-than sign replaced.
   108  * Returns a string with greater-than sign replaced.
    99  *
   109  *
   109 function __unstableEscapeGreaterThan(value) {
   119 function __unstableEscapeGreaterThan(value) {
   110   return value.replace(/>/g, '>');
   120   return value.replace(/>/g, '>');
   111 }
   121 }
   112 
   122 
   113 // CONCATENATED MODULE: ./node_modules/@wordpress/escape-html/build-module/index.js
   123 // CONCATENATED MODULE: ./node_modules/@wordpress/escape-html/build-module/index.js
   114 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "escapeAmpersand", function() { return escapeAmpersand; });
       
   115 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "escapeQuotationMark", function() { return escapeQuotationMark; });
       
   116 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "escapeLessThan", function() { return escapeLessThan; });
       
   117 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "escapeAttribute", function() { return escapeAttribute; });
       
   118 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "escapeHTML", function() { return escapeHTML; });
       
   119 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isValidAttributeName", function() { return isValidAttributeName; });
       
   120 /**
   124 /**
   121  * Internal dependencies
   125  * Internal dependencies
   122  */
   126  */
   123 
   127 
   124 /**
   128 /**
   126  *
   130  *
   127  * "Attribute names must consist of one or more characters other than controls,
   131  * "Attribute names must consist of one or more characters other than controls,
   128  * U+0020 SPACE, U+0022 ("), U+0027 ('), U+003E (>), U+002F (/), U+003D (=),
   132  * U+0020 SPACE, U+0022 ("), U+0027 ('), U+003E (>), U+002F (/), U+003D (=),
   129  * and noncharacters."
   133  * and noncharacters."
   130  *
   134  *
   131  * @link https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
   135  * @see https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
   132  *
   136  *
   133  * @type {RegExp}
   137  * @type {RegExp}
   134  */
   138  */
   135 
   139 
   136 var REGEXP_INVALID_ATTRIBUTE_NAME = /[\u007F-\u009F "'>/="\uFDD0-\uFDEF]/;
   140 var REGEXP_INVALID_ATTRIBUTE_NAME = /[\u007F-\u009F "'>/="\uFDD0-\uFDEF]/;
   138  * Returns a string with ampersands escaped. Note that this is an imperfect
   142  * Returns a string with ampersands escaped. Note that this is an imperfect
   139  * implementation, where only ampersands which do not appear as a pattern of
   143  * implementation, where only ampersands which do not appear as a pattern of
   140  * named, decimal, or hexadecimal character references are escaped. Invalid
   144  * named, decimal, or hexadecimal character references are escaped. Invalid
   141  * named references (i.e. ambiguous ampersand) are are still permitted.
   145  * named references (i.e. ambiguous ampersand) are are still permitted.
   142  *
   146  *
   143  * @link https://w3c.github.io/html/syntax.html#character-references
   147  * @see https://w3c.github.io/html/syntax.html#character-references
   144  * @link https://w3c.github.io/html/syntax.html#ambiguous-ampersand
   148  * @see https://w3c.github.io/html/syntax.html#ambiguous-ampersand
   145  * @link https://w3c.github.io/html/syntax.html#named-character-references
   149  * @see https://w3c.github.io/html/syntax.html#named-character-references
   146  *
   150  *
   147  * @param {string} value Original string.
   151  * @param {string} value Original string.
   148  *
   152  *
   149  * @return {string} Escaped string.
   153  * @return {string} Escaped string.
   150  */
   154  */
   175   return value.replace(/</g, '&lt;');
   179   return value.replace(/</g, '&lt;');
   176 }
   180 }
   177 /**
   181 /**
   178  * Returns an escaped attribute value.
   182  * Returns an escaped attribute value.
   179  *
   183  *
   180  * @link https://w3c.github.io/html/syntax.html#elements-attributes
   184  * @see https://w3c.github.io/html/syntax.html#elements-attributes
   181  *
   185  *
   182  * "[...] the text cannot contain an ambiguous ampersand [...] must not contain
   186  * "[...] the text cannot contain an ambiguous ampersand [...] must not contain
   183  * any literal U+0022 QUOTATION MARK characters (")"
   187  * any literal U+0022 QUOTATION MARK characters (")"
   184  *
   188  *
   185  * Note we also escape the greater than symbol, as this is used by wptexturize to
   189  * Note we also escape the greater than symbol, as this is used by wptexturize to
   199   return __unstableEscapeGreaterThan(escapeQuotationMark(escapeAmpersand(value)));
   203   return __unstableEscapeGreaterThan(escapeQuotationMark(escapeAmpersand(value)));
   200 }
   204 }
   201 /**
   205 /**
   202  * Returns an escaped HTML element value.
   206  * Returns an escaped HTML element value.
   203  *
   207  *
   204  * @link https://w3c.github.io/html/syntax.html#writing-html-documents-elements
   208  * @see https://w3c.github.io/html/syntax.html#writing-html-documents-elements
   205  *
   209  *
   206  * "the text must not contain the character U+003C LESS-THAN SIGN (<) or an
   210  * "the text must not contain the character U+003C LESS-THAN SIGN (<) or an
   207  * ambiguous ampersand."
   211  * ambiguous ampersand."
   208  *
   212  *
   209  * @param {string} value Element value.
   213  * @param {string} value Element value.
   213 
   217 
   214 function escapeHTML(value) {
   218 function escapeHTML(value) {
   215   return escapeLessThan(escapeAmpersand(value));
   219   return escapeLessThan(escapeAmpersand(value));
   216 }
   220 }
   217 /**
   221 /**
       
   222  * Returns an escaped Editable HTML element value. This is different from
       
   223  * `escapeHTML`, because for editable HTML, ALL ampersands must be escaped in
       
   224  * order to render the content correctly on the page.
       
   225  *
       
   226  * @param {string} value Element value.
       
   227  *
       
   228  * @return {string} Escaped HTML element value.
       
   229  */
       
   230 
       
   231 function escapeEditableHTML(value) {
       
   232   return escapeLessThan(value.replace(/&/g, '&amp;'));
       
   233 }
       
   234 /**
   218  * Returns true if the given attribute name is valid, or false otherwise.
   235  * Returns true if the given attribute name is valid, or false otherwise.
   219  *
   236  *
   220  * @param {string} name Attribute name to test.
   237  * @param {string} name Attribute name to test.
   221  *
   238  *
   222  * @return {boolean} Whether attribute is valid.
   239  * @return {boolean} Whether attribute is valid.