[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/js/dist/ -> escape-html.js (source)

   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: ./node_modules/@wordpress/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: ./node_modules/@wordpress/escape-html/build-module/index.js
  69  /**
  70   * Internal dependencies
  71   */
  72  
  73  /**
  74   * Regular expression matching invalid attribute names.
  75   *
  76   * "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   * and noncharacters."
  79   *
  80   * @see https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
  81   *
  82   * @type {RegExp}
  83   */
  84  
  85  const REGEXP_INVALID_ATTRIBUTE_NAME = /[\u007F-\u009F "'>/="\uFDD0-\uFDEF]/;
  86  /**
  87   * 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   * named, decimal, or hexadecimal character references are escaped. Invalid
  90   * named references (i.e. ambiguous ampersand) are are still permitted.
  91   *
  92   * @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#named-character-references
  95   *
  96   * @param {string} value Original string.
  97   *
  98   * @return {string} Escaped string.
  99   */
 100  
 101  function escapeAmpersand(value) {
 102    return value.replace(/&(?!([a-z0-9]+|#[0-9]+|#x[a-f0-9]+);)/gi, '&');
 103  }
 104  /**
 105   * Returns a string with quotation marks replaced.
 106   *
 107   * @param {string} value Original string.
 108   *
 109   * @return {string} Escaped string.
 110   */
 111  
 112  function escapeQuotationMark(value) {
 113    return value.replace(/"/g, '"');
 114  }
 115  /**
 116   * Returns a string with less-than sign replaced.
 117   *
 118   * @param {string} value Original string.
 119   *
 120   * @return {string} Escaped string.
 121   */
 122  
 123  function escapeLessThan(value) {
 124    return value.replace(/</g, '&lt;');
 125  }
 126  /**
 127   * Returns an escaped attribute value.
 128   *
 129   * @see https://w3c.github.io/html/syntax.html#elements-attributes
 130   *
 131   * "[...] the text cannot contain an ambiguous ampersand [...] must not contain
 132   * any literal U+0022 QUOTATION MARK characters (")"
 133   *
 134   * Note we also escape the greater than symbol, as this is used by wptexturize to
 135   * split HTML strings. This is a WordPress specific fix
 136   *
 137   * Note that if a resolution for Trac#45387 comes to fruition, it is no longer
 138   * necessary for `__unstableEscapeGreaterThan` to be used.
 139   *
 140   * See: https://core.trac.wordpress.org/ticket/45387
 141   *
 142   * @param {string} value Attribute value.
 143   *
 144   * @return {string} Escaped attribute value.
 145   */
 146  
 147  function escapeAttribute(value) {
 148    return __unstableEscapeGreaterThan(escapeQuotationMark(escapeAmpersand(value)));
 149  }
 150  /**
 151   * Returns an escaped HTML element value.
 152   *
 153   * @see https://w3c.github.io/html/syntax.html#writing-html-documents-elements
 154   *
 155   * "the text must not contain the character U+003C LESS-THAN SIGN (<) or an
 156   * ambiguous ampersand."
 157   *
 158   * @param {string} value Element value.
 159   *
 160   * @return {string} Escaped HTML element value.
 161   */
 162  
 163  function escapeHTML(value) {
 164    return escapeLessThan(escapeAmpersand(value));
 165  }
 166  /**
 167   * Returns an escaped Editable HTML element value. This is different from
 168   * `escapeHTML`, because for editable HTML, ALL ampersands must be escaped in
 169   * order to render the content correctly on the page.
 170   *
 171   * @param {string} value Element value.
 172   *
 173   * @return {string} Escaped HTML element value.
 174   */
 175  
 176  function escapeEditableHTML(value) {
 177    return escapeLessThan(value.replace(/&/g, '&amp;'));
 178  }
 179  /**
 180   * Returns true if the given attribute name is valid, or false otherwise.
 181   *
 182   * @param {string} name Attribute name to test.
 183   *
 184   * @return {boolean} Whether attribute is valid.
 185   */
 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  ;


Generated: Sat Dec 21 01:00:02 2024 Cross-referenced by PHPXref 0.7.1