escape-html.js 6.2 KB

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