[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  /******/ (() => { // webpackBootstrap
   2  /******/     "use strict";
   3  /******/     // The require scope
   4  /******/     var __webpack_require__ = {};
   5  /******/     
   6  /************************************************************************/
   7  /******/     /* webpack/runtime/define property getters */
   8  /******/     (() => {
   9  /******/         // define getter functions for harmony exports
  10  /******/         __webpack_require__.d = (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  /******/     (() => {
  21  /******/         __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  22  /******/     })();
  23  /******/     
  24  /******/     /* webpack/runtime/make namespace object */
  25  /******/     (() => {
  26  /******/         // define __esModule on exports
  27  /******/         __webpack_require__.r = (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: () => (/* binding */ escapeAmpersand),
  43    escapeAttribute: () => (/* binding */ escapeAttribute),
  44    escapeEditableHTML: () => (/* binding */ escapeEditableHTML),
  45    escapeHTML: () => (/* binding */ escapeHTML),
  46    escapeLessThan: () => (/* binding */ escapeLessThan),
  47    escapeQuotationMark: () => (/* binding */ escapeQuotationMark),
  48    isValidAttributeName: () => (/* binding */ isValidAttributeName)
  49  });
  50  
  51  ;// ./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 value Original string.
  61   *
  62   * @return Escaped string.
  63   */
  64  function __unstableEscapeGreaterThan(value) {
  65    return value.replace(/>/g, '>');
  66  }
  67  
  68  ;// ./node_modules/@wordpress/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  const REGEXP_INVALID_ATTRIBUTE_NAME = /[\u007F-\u009F "'>/="\uFDD0-\uFDEF]/;
  84  
  85  /**
  86   * Returns a string with ampersands escaped. Note that this is an imperfect
  87   * implementation, where only ampersands which do not appear as a pattern of
  88   * named, decimal, or hexadecimal character references are escaped. Invalid
  89   * named references (i.e. ambiguous ampersand) are still permitted.
  90   *
  91   * @see https://w3c.github.io/html/syntax.html#character-references
  92   * @see https://w3c.github.io/html/syntax.html#ambiguous-ampersand
  93   * @see https://w3c.github.io/html/syntax.html#named-character-references
  94   *
  95   * @param value Original string.
  96   *
  97   * @return Escaped string.
  98   */
  99  function escapeAmpersand(value) {
 100    return value.replace(/&(?!([a-z0-9]+|#[0-9]+|#x[a-f0-9]+);)/gi, '&');
 101  }
 102  
 103  /**
 104   * Returns a string with quotation marks replaced.
 105   *
 106   * @param value Original string.
 107   *
 108   * @return Escaped string.
 109   */
 110  function escapeQuotationMark(value) {
 111    return value.replace(/"/g, '"');
 112  }
 113  
 114  /**
 115   * Returns a string with less-than sign replaced.
 116   *
 117   * @param value Original string.
 118   *
 119   * @return Escaped string.
 120   */
 121  function escapeLessThan(value) {
 122    return value.replace(/</g, '&lt;');
 123  }
 124  
 125  /**
 126   * Returns an escaped attribute value.
 127   *
 128   * @see https://w3c.github.io/html/syntax.html#elements-attributes
 129   *
 130   * "[...] the text cannot contain an ambiguous ampersand [...] must not contain
 131   * any literal U+0022 QUOTATION MARK characters (")"
 132   *
 133   * Note we also escape the greater than symbol, as this is used by wptexturize to
 134   * split HTML strings. This is a WordPress specific fix
 135   *
 136   * Note that if a resolution for Trac#45387 comes to fruition, it is no longer
 137   * necessary for `__unstableEscapeGreaterThan` to be used.
 138   *
 139   * See: https://core.trac.wordpress.org/ticket/45387
 140   *
 141   * @param value Attribute value.
 142   *
 143   * @return Escaped attribute value.
 144   */
 145  function escapeAttribute(value) {
 146    return __unstableEscapeGreaterThan(escapeQuotationMark(escapeAmpersand(value)));
 147  }
 148  
 149  /**
 150   * Returns an escaped HTML element value.
 151   *
 152   * @see https://w3c.github.io/html/syntax.html#writing-html-documents-elements
 153   *
 154   * "the text must not contain the character U+003C LESS-THAN SIGN (<) or an
 155   * ambiguous ampersand."
 156   *
 157   * @param value Element value.
 158   *
 159   * @return Escaped HTML element value.
 160   */
 161  function escapeHTML(value) {
 162    return escapeLessThan(escapeAmpersand(value));
 163  }
 164  
 165  /**
 166   * Returns an escaped Editable HTML element value. This is different from
 167   * `escapeHTML`, because for editable HTML, ALL ampersands must be escaped in
 168   * order to render the content correctly on the page.
 169   *
 170   * @param value Element value.
 171   *
 172   * @return Escaped HTML element value.
 173   */
 174  function escapeEditableHTML(value) {
 175    return escapeLessThan(value.replace(/&/g, '&amp;'));
 176  }
 177  
 178  /**
 179   * Returns true if the given attribute name is valid, or false otherwise.
 180   *
 181   * @param name Attribute name to test.
 182   *
 183   * @return Whether attribute is valid.
 184   */
 185  function isValidAttributeName(name) {
 186    return !REGEXP_INVALID_ATTRIBUTE_NAME.test(name);
 187  }
 188  
 189  (window.wp = window.wp || {}).escapeHtml = __webpack_exports__;
 190  /******/ })()
 191  ;


Generated : Sat Dec 21 08:20:01 2024 Cross-referenced by PHPXref