@prunellejs/icons 0.7.3 → 0.7.7

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/svg-dir.ts +8 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prunellejs/icons",
3
- "version": "0.7.3",
3
+ "version": "0.7.7",
4
4
  "description": "Compile-time Iconify SVG icon plugin (~icons/<set>/<name>) for Prunelle",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,6 +24,6 @@
24
24
  "directory": "packages/plugin-icons"
25
25
  },
26
26
  "peerDependencies": {
27
- "prunelle": "^0.7.3"
27
+ "prunelle": "^0.7.7"
28
28
  }
29
29
  }
package/src/svg-dir.ts CHANGED
@@ -23,7 +23,7 @@ export interface SvgDirSet {
23
23
  }
24
24
 
25
25
  const SCRIPT_TAG_RE = /<script\b/i
26
- const EVENT_ATTR_RE = /(?:[\s/"'])on[a-z]+\s*=/i
26
+ const EVENT_ATTR_RE = /^on[a-z]+$/i
27
27
  const HTML_ENTITY_RE = /&(?:#x([0-9a-f]+);?|#(\d+);?|([a-z]+);)/gi
28
28
  const JAVASCRIPT_URL_RE = /(?:^|;)javascript:/i
29
29
  const VBSCRIPT_URL_RE = /(?:^|;)vbscript:/i
@@ -87,11 +87,13 @@ export function svgHazard(source: string): string | undefined {
87
87
  if (SCRIPT_TAG_RE.test(text))
88
88
  return 'a <script> element'
89
89
  for (const [tag] of text.matchAll(TAG_RE)) {
90
- const inner = tag.slice(1, -1)
91
- if (EVENT_ATTR_RE.test(inner))
92
- return 'an on* event attribute'
93
- for (const [, , double, single, unquoted] of inner.matchAll(TAG_ATTR_RE)) {
94
- const hazard = urlHazard(double ?? single ?? unquoted ?? '')
90
+ // Attributes are read whole, so `on…=` text inside a quoted value is not taken for a handler.
91
+ for (const [, name, double, single, unquoted] of tag.slice(1, -1).matchAll(TAG_ATTR_RE)) {
92
+ if (EVENT_ATTR_RE.test(name!))
93
+ return 'an on* event attribute'
94
+ const value = double ?? single ?? unquoted ?? ''
95
+ // An iframe's srcdoc is a whole HTML page once its entities are decoded.
96
+ const hazard = name!.toLowerCase() === 'srcdoc' ? svgHazard(decodeHtmlEntities(value)) : urlHazard(value)
95
97
  if (hazard !== undefined)
96
98
  return hazard
97
99
  }