sanitize-html 2.5.1 → 2.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.5.2 (2021-10-13):
4
+
5
+ - Nullish HTML input now returns an empty string. Nullish value may be explicit `null`, `undefined` or implicit `undefined` when value is not provided. Thanks to Artem Kostiuk for the contribution.
6
+ - Documented that all text content is escaped. Thanks to Siddharth Singh.
7
+
3
8
  ## 2.5.1 (2021-09-14):
4
9
  - The `allowedScriptHostnames` and `allowedScriptDomains` options now implicitly purge the inline content of all script tags, not just those with `src` attributes. This behavior was already strongly implied by the fact that they purged it in the case where a `src` attribute was actually present, and is necessary for the feature to provide any real security. Thanks to Grigorii Duca for pointing out the issue.
5
10
 
package/README.md CHANGED
@@ -21,6 +21,7 @@ The syntax of poorly closed `p` and `img` elements is cleaned up.
21
21
  Allowing particular urls as a `src` to an iframe tag by filtering hostnames is also supported.
22
22
 
23
23
  HTML comments are not preserved.
24
+ Additionally, `sanitize-html` escapes _ALL_ text content - this means that ampersands, greater-than, and less-than signs are converted to their equivalent HTML character references (`&` --> `&amp;`, `<` --> `&lt;`, and so on). Additionally, in attribute values, quotation marks are escaped as well (`"` --> `&quot;`).
24
25
 
25
26
  ## Requirements
26
27
 
package/index.js CHANGED
@@ -81,6 +81,10 @@ const VALID_HTML_ATTRIBUTE_NAME = /^[^\0\t\n\f\r /<=>]+$/;
81
81
  // https://github.com/fb55/htmlparser2/issues/105
82
82
 
83
83
  function sanitizeHtml(html, options, _recursing) {
84
+ if (html == null) {
85
+ return '';
86
+ }
87
+
84
88
  let result = '';
85
89
  // Used for hot swapping the result variable with an empty string in order to "capture" the text written to it.
86
90
  let tempResult = '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanitize-html",
3
- "version": "2.5.1",
3
+ "version": "2.5.2",
4
4
  "description": "Clean up user-submitted HTML, preserving allowlisted elements and allowlisted attributes on a per-element basis",
5
5
  "sideEffects": false,
6
6
  "main": "index.js",