wp/wp-includes/js/dist/escape-html.js
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     1 /******/ (function() { // webpackBootstrap
     1 /******/ (() => { // webpackBootstrap
     2 /******/ 	"use strict";
     2 /******/ 	"use strict";
     3 /******/ 	// The require scope
     3 /******/ 	// The require scope
     4 /******/ 	var __webpack_require__ = {};
     4 /******/ 	var __webpack_require__ = {};
     5 /******/ 	
     5 /******/ 	
     6 /************************************************************************/
     6 /************************************************************************/
     7 /******/ 	/* webpack/runtime/define property getters */
     7 /******/ 	/* webpack/runtime/define property getters */
     8 /******/ 	!function() {
     8 /******/ 	(() => {
     9 /******/ 		// define getter functions for harmony exports
     9 /******/ 		// define getter functions for harmony exports
    10 /******/ 		__webpack_require__.d = function(exports, definition) {
    10 /******/ 		__webpack_require__.d = (exports, definition) => {
    11 /******/ 			for(var key in definition) {
    11 /******/ 			for(var key in definition) {
    12 /******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
    12 /******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
    13 /******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
    13 /******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
    14 /******/ 				}
    14 /******/ 				}
    15 /******/ 			}
    15 /******/ 			}
    16 /******/ 		};
    16 /******/ 		};
    17 /******/ 	}();
    17 /******/ 	})();
    18 /******/ 	
    18 /******/ 	
    19 /******/ 	/* webpack/runtime/hasOwnProperty shorthand */
    19 /******/ 	/* webpack/runtime/hasOwnProperty shorthand */
    20 /******/ 	!function() {
    20 /******/ 	(() => {
    21 /******/ 		__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
    21 /******/ 		__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
    22 /******/ 	}();
    22 /******/ 	})();
    23 /******/ 	
    23 /******/ 	
    24 /******/ 	/* webpack/runtime/make namespace object */
    24 /******/ 	/* webpack/runtime/make namespace object */
    25 /******/ 	!function() {
    25 /******/ 	(() => {
    26 /******/ 		// define __esModule on exports
    26 /******/ 		// define __esModule on exports
    27 /******/ 		__webpack_require__.r = function(exports) {
    27 /******/ 		__webpack_require__.r = (exports) => {
    28 /******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
    28 /******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
    29 /******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
    29 /******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
    30 /******/ 			}
    30 /******/ 			}
    31 /******/ 			Object.defineProperty(exports, '__esModule', { value: true });
    31 /******/ 			Object.defineProperty(exports, '__esModule', { value: true });
    32 /******/ 		};
    32 /******/ 		};
    33 /******/ 	}();
    33 /******/ 	})();
    34 /******/ 	
    34 /******/ 	
    35 /************************************************************************/
    35 /************************************************************************/
    36 var __webpack_exports__ = {};
    36 var __webpack_exports__ = {};
    37 // ESM COMPAT FLAG
    37 // ESM COMPAT FLAG
    38 __webpack_require__.r(__webpack_exports__);
    38 __webpack_require__.r(__webpack_exports__);
    39 
    39 
    40 // EXPORTS
    40 // EXPORTS
    41 __webpack_require__.d(__webpack_exports__, {
    41 __webpack_require__.d(__webpack_exports__, {
    42   "escapeAmpersand": function() { return /* binding */ escapeAmpersand; },
    42   escapeAmpersand: () => (/* binding */ escapeAmpersand),
    43   "escapeAttribute": function() { return /* binding */ escapeAttribute; },
    43   escapeAttribute: () => (/* binding */ escapeAttribute),
    44   "escapeEditableHTML": function() { return /* binding */ escapeEditableHTML; },
    44   escapeEditableHTML: () => (/* binding */ escapeEditableHTML),
    45   "escapeHTML": function() { return /* binding */ escapeHTML; },
    45   escapeHTML: () => (/* binding */ escapeHTML),
    46   "escapeLessThan": function() { return /* binding */ escapeLessThan; },
    46   escapeLessThan: () => (/* binding */ escapeLessThan),
    47   "escapeQuotationMark": function() { return /* binding */ escapeQuotationMark; },
    47   escapeQuotationMark: () => (/* binding */ escapeQuotationMark),
    48   "isValidAttributeName": function() { return /* binding */ isValidAttributeName; }
    48   isValidAttributeName: () => (/* binding */ isValidAttributeName)
    49 });
    49 });
    50 
    50 
    51 ;// CONCATENATED MODULE: ./node_modules/@wordpress/escape-html/build-module/escape-greater.js
    51 ;// CONCATENATED MODULE: ./node_modules/@wordpress/escape-html/build-module/escape-greater.js
    52 /**
    52 /**
    53  * Returns a string with greater-than sign replaced.
    53  * Returns a string with greater-than sign replaced.
    68 ;// CONCATENATED MODULE: ./node_modules/@wordpress/escape-html/build-module/index.js
    68 ;// CONCATENATED MODULE: ./node_modules/@wordpress/escape-html/build-module/index.js
    69 /**
    69 /**
    70  * Internal dependencies
    70  * Internal dependencies
    71  */
    71  */
    72 
    72 
       
    73 
    73 /**
    74 /**
    74  * Regular expression matching invalid attribute names.
    75  * Regular expression matching invalid attribute names.
    75  *
    76  *
    76  * "Attribute names must consist of one or more characters other than controls,
    77  * "Attribute names must consist of one or more characters other than controls,
    77  * U+0020 SPACE, U+0022 ("), U+0027 ('), U+003E (>), U+002F (/), U+003D (=),
    78  * U+0020 SPACE, U+0022 ("), U+0027 ('), U+003E (>), U+002F (/), U+003D (=),
    79  *
    80  *
    80  * @see https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
    81  * @see https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
    81  *
    82  *
    82  * @type {RegExp}
    83  * @type {RegExp}
    83  */
    84  */
       
    85 const REGEXP_INVALID_ATTRIBUTE_NAME = /[\u007F-\u009F "'>/="\uFDD0-\uFDEF]/;
    84 
    86 
    85 const REGEXP_INVALID_ATTRIBUTE_NAME = /[\u007F-\u009F "'>/="\uFDD0-\uFDEF]/;
       
    86 /**
    87 /**
    87  * Returns a string with ampersands escaped. Note that this is an imperfect
    88  * Returns a string with ampersands escaped. Note that this is an imperfect
    88  * implementation, where only ampersands which do not appear as a pattern of
    89  * implementation, where only ampersands which do not appear as a pattern of
    89  * named, decimal, or hexadecimal character references are escaped. Invalid
    90  * named, decimal, or hexadecimal character references are escaped. Invalid
    90  * named references (i.e. ambiguous ampersand) are are still permitted.
    91  * named references (i.e. ambiguous ampersand) are still permitted.
    91  *
    92  *
    92  * @see https://w3c.github.io/html/syntax.html#character-references
    93  * @see https://w3c.github.io/html/syntax.html#character-references
    93  * @see https://w3c.github.io/html/syntax.html#ambiguous-ampersand
    94  * @see https://w3c.github.io/html/syntax.html#ambiguous-ampersand
    94  * @see https://w3c.github.io/html/syntax.html#named-character-references
    95  * @see https://w3c.github.io/html/syntax.html#named-character-references
    95  *
    96  *
    96  * @param {string} value Original string.
    97  * @param {string} value Original string.
    97  *
    98  *
    98  * @return {string} Escaped string.
    99  * @return {string} Escaped string.
    99  */
   100  */
   100 
       
   101 function escapeAmpersand(value) {
   101 function escapeAmpersand(value) {
   102   return value.replace(/&(?!([a-z0-9]+|#[0-9]+|#x[a-f0-9]+);)/gi, '&');
   102   return value.replace(/&(?!([a-z0-9]+|#[0-9]+|#x[a-f0-9]+);)/gi, '&');
   103 }
   103 }
       
   104 
   104 /**
   105 /**
   105  * Returns a string with quotation marks replaced.
   106  * Returns a string with quotation marks replaced.
   106  *
   107  *
   107  * @param {string} value Original string.
   108  * @param {string} value Original string.
   108  *
   109  *
   109  * @return {string} Escaped string.
   110  * @return {string} Escaped string.
   110  */
   111  */
   111 
       
   112 function escapeQuotationMark(value) {
   112 function escapeQuotationMark(value) {
   113   return value.replace(/"/g, '"');
   113   return value.replace(/"/g, '"');
   114 }
   114 }
       
   115 
   115 /**
   116 /**
   116  * Returns a string with less-than sign replaced.
   117  * Returns a string with less-than sign replaced.
   117  *
   118  *
   118  * @param {string} value Original string.
   119  * @param {string} value Original string.
   119  *
   120  *
   120  * @return {string} Escaped string.
   121  * @return {string} Escaped string.
   121  */
   122  */
   122 
       
   123 function escapeLessThan(value) {
   123 function escapeLessThan(value) {
   124   return value.replace(/</g, '&lt;');
   124   return value.replace(/</g, '&lt;');
   125 }
   125 }
       
   126 
   126 /**
   127 /**
   127  * Returns an escaped attribute value.
   128  * Returns an escaped attribute value.
   128  *
   129  *
   129  * @see https://w3c.github.io/html/syntax.html#elements-attributes
   130  * @see https://w3c.github.io/html/syntax.html#elements-attributes
   130  *
   131  *
   141  *
   142  *
   142  * @param {string} value Attribute value.
   143  * @param {string} value Attribute value.
   143  *
   144  *
   144  * @return {string} Escaped attribute value.
   145  * @return {string} Escaped attribute value.
   145  */
   146  */
   146 
       
   147 function escapeAttribute(value) {
   147 function escapeAttribute(value) {
   148   return __unstableEscapeGreaterThan(escapeQuotationMark(escapeAmpersand(value)));
   148   return __unstableEscapeGreaterThan(escapeQuotationMark(escapeAmpersand(value)));
   149 }
   149 }
       
   150 
   150 /**
   151 /**
   151  * Returns an escaped HTML element value.
   152  * Returns an escaped HTML element value.
   152  *
   153  *
   153  * @see https://w3c.github.io/html/syntax.html#writing-html-documents-elements
   154  * @see https://w3c.github.io/html/syntax.html#writing-html-documents-elements
   154  *
   155  *
   157  *
   158  *
   158  * @param {string} value Element value.
   159  * @param {string} value Element value.
   159  *
   160  *
   160  * @return {string} Escaped HTML element value.
   161  * @return {string} Escaped HTML element value.
   161  */
   162  */
   162 
       
   163 function escapeHTML(value) {
   163 function escapeHTML(value) {
   164   return escapeLessThan(escapeAmpersand(value));
   164   return escapeLessThan(escapeAmpersand(value));
   165 }
   165 }
       
   166 
   166 /**
   167 /**
   167  * Returns an escaped Editable HTML element value. This is different from
   168  * Returns an escaped Editable HTML element value. This is different from
   168  * `escapeHTML`, because for editable HTML, ALL ampersands must be escaped in
   169  * `escapeHTML`, because for editable HTML, ALL ampersands must be escaped in
   169  * order to render the content correctly on the page.
   170  * order to render the content correctly on the page.
   170  *
   171  *
   171  * @param {string} value Element value.
   172  * @param {string} value Element value.
   172  *
   173  *
   173  * @return {string} Escaped HTML element value.
   174  * @return {string} Escaped HTML element value.
   174  */
   175  */
   175 
       
   176 function escapeEditableHTML(value) {
   176 function escapeEditableHTML(value) {
   177   return escapeLessThan(value.replace(/&/g, '&amp;'));
   177   return escapeLessThan(value.replace(/&/g, '&amp;'));
   178 }
   178 }
       
   179 
   179 /**
   180 /**
   180  * Returns true if the given attribute name is valid, or false otherwise.
   181  * Returns true if the given attribute name is valid, or false otherwise.
   181  *
   182  *
   182  * @param {string} name Attribute name to test.
   183  * @param {string} name Attribute name to test.
   183  *
   184  *
   184  * @return {boolean} Whether attribute is valid.
   185  * @return {boolean} Whether attribute is valid.
   185  */
   186  */
   186 
       
   187 function isValidAttributeName(name) {
   187 function isValidAttributeName(name) {
   188   return !REGEXP_INVALID_ATTRIBUTE_NAME.test(name);
   188   return !REGEXP_INVALID_ATTRIBUTE_NAME.test(name);
   189 }
   189 }
   190 
   190 
   191 (window.wp = window.wp || {}).escapeHtml = __webpack_exports__;
   191 (window.wp = window.wp || {}).escapeHtml = __webpack_exports__;