PluginProbe
Gutenberg / 17.2.4
Gutenberg v17.2.4
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / build / escape-html / index.js

index.js in Gutenberg 17.2.4, at build/escape-html/index.js

193 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
40 // EXPORTS
41 __webpack_require__.d(__webpack_exports__, {
42 escapeAmpersand: function() { return /* binding */ escapeAmpersand; },
43 escapeAttribute: function() { return /* binding */ escapeAttribute; },
44 escapeEditableHTML: function() { return /* binding */ escapeEditableHTML; },
45 escapeHTML: function() { return /* binding */ escapeHTML; },
46 escapeLessThan: function() { return /* binding */ escapeLessThan; },
47 escapeQuotationMark: function() { return /* binding */ escapeQuotationMark; },
48 isValidAttributeName: function() { return /* binding */ isValidAttributeName; }
49 });
50
51 ;// CONCATENATED MODULE: ./packages/escape-html/build-module/escape-greater.js
52 /**
53 * Returns a string with greater-than sign replaced.
54 *
55 * Note that if a resolution for Trac#45387 comes to fruition, it is no longer
56 * necessary for `__unstableEscapeGreaterThan` to exist.
57 *
58 * See: https://core.trac.wordpress.org/ticket/45387
59 *
60 * @param {string} value Original string.
61 *
62 * @return {string} Escaped string.
63 */
64 function __unstableEscapeGreaterThan(value) {
65 return value.replace(/>/g, '>');
66 }
67
68 ;// CONCATENATED MODULE: ./packages/escape-html/build-module/index.js
69 /**
70 * Internal dependencies
71 */
72
73
74 /**
75 * Regular expression matching invalid attribute names.
76 *
77 * "Attribute names must consist of one or more characters other than controls,
78 * U+0020 SPACE, U+0022 ("), U+0027 ('), U+003E (>), U+002F (/), U+003D (=),
79 * and noncharacters."
80 *
81 * @see https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
82 *
83 * @type {RegExp}
84 */
85 const REGEXP_INVALID_ATTRIBUTE_NAME = /[\u007F-\u009F "'>/="\uFDD0-\uFDEF]/;
86
87 /**
88 * Returns a string with ampersands escaped. Note that this is an imperfect
89 * implementation, where only ampersands which do not appear as a pattern of
90 * named, decimal, or hexadecimal character references are escaped. Invalid
91 * named references (i.e. ambiguous ampersand) are still permitted.
92 *
93 * @see https://w3c.github.io/html/syntax.html#character-references
94 * @see https://w3c.github.io/html/syntax.html#ambiguous-ampersand
95 * @see https://w3c.github.io/html/syntax.html#named-character-references
96 *
97 * @param {string} value Original string.
98 *
99 * @return {string} Escaped string.
100 */
101 function escapeAmpersand(value) {
102 return value.replace(/&(?!([a-z0-9]+|#[0-9]+|#x[a-f0-9]+);)/gi, '&');
103 }
104
105 /**
106 * Returns a string with quotation marks replaced.
107 *
108 * @param {string} value Original string.
109 *
110 * @return {string} Escaped string.
111 */
112 function escapeQuotationMark(value) {
113 return value.replace(/"/g, '"');
114 }
115
116 /**
117 * Returns a string with less-than sign replaced.
118 *
119 * @param {string} value Original string.
120 *
121 * @return {string} Escaped string.
122 */
123 function escapeLessThan(value) {
124 return value.replace(/</g, '&lt;');
125 }
126
127 /**
128 * Returns an escaped attribute value.
129 *
130 * @see https://w3c.github.io/html/syntax.html#elements-attributes
131 *
132 * "[...] the text cannot contain an ambiguous ampersand [...] must not contain
133 * any literal U+0022 QUOTATION MARK characters (")"
134 *
135 * Note we also escape the greater than symbol, as this is used by wptexturize to
136 * split HTML strings. This is a WordPress specific fix
137 *
138 * Note that if a resolution for Trac#45387 comes to fruition, it is no longer
139 * necessary for `__unstableEscapeGreaterThan` to be used.
140 *
141 * See: https://core.trac.wordpress.org/ticket/45387
142 *
143 * @param {string} value Attribute value.
144 *
145 * @return {string} Escaped attribute value.
146 */
147 function escapeAttribute(value) {
148 return __unstableEscapeGreaterThan(escapeQuotationMark(escapeAmpersand(value)));
149 }
150
151 /**
152 * Returns an escaped HTML element value.
153 *
154 * @see https://w3c.github.io/html/syntax.html#writing-html-documents-elements
155 *
156 * "the text must not contain the character U+003C LESS-THAN SIGN (<) or an
157 * ambiguous ampersand."
158 *
159 * @param {string} value Element value.
160 *
161 * @return {string} Escaped HTML element value.
162 */
163 function escapeHTML(value) {
164 return escapeLessThan(escapeAmpersand(value));
165 }
166
167 /**
168 * Returns an escaped Editable HTML element value. This is different from
169 * `escapeHTML`, because for editable HTML, ALL ampersands must be escaped in
170 * order to render the content correctly on the page.
171 *
172 * @param {string} value Element value.
173 *
174 * @return {string} Escaped HTML element value.
175 */
176 function escapeEditableHTML(value) {
177 return escapeLessThan(value.replace(/&/g, '&amp;'));
178 }
179
180 /**
181 * Returns true if the given attribute name is valid, or false otherwise.
182 *
183 * @param {string} name Attribute name to test.
184 *
185 * @return {boolean} Whether attribute is valid.
186 */
187 function isValidAttributeName(name) {
188 return !REGEXP_INVALID_ATTRIBUTE_NAME.test(name);
189 }
190
191 (window.wp = window.wp || {}).escapeHtml = __webpack_exports__;
192 /******/ })()
193 ;