diff --git a/scripts/lib/svg-active-content.mjs b/scripts/lib/svg-active-content.mjs index 322bf53f..f886b89d 100644 --- a/scripts/lib/svg-active-content.mjs +++ b/scripts/lib/svg-active-content.mjs @@ -210,11 +210,74 @@ const RESOURCE_ELEMENTS = new Set([ const TAG_PATTERN = /<\s*([A-Za-z_][-A-Za-z0-9_.:]*)((?:"[^"]*"|'[^']*'|[^>"'])*)>/g; -const STYLE_BLOCK_PATTERN = new RegExp( - `<\\s*${NS_PREFIX}style\\b(?:"[^"]*"|'[^']*'|[^>"'])*>([\\s\\S]*?)<\\s*/\\s*${NS_PREFIX}style\\s*>`, +const STYLE_OPEN_TAG = new RegExp( + `<\\s*${NS_PREFIX}style\\b((?:"[^"]*"|'[^']*'|[^>"'])*)>`, 'gi', ); +/** Sticky, so the close tag can be tested in place without slicing. */ +const STYLE_CLOSE_TAG = new RegExp(`<\\s*/\\s*${NS_PREFIX}style\\s*>`, 'iy'); + +const CDATA_OPEN = ''; + +/** + * The CSS text of every `` regex cannot express this. In + * XML -- which is how a browser parses a standalone `.svg` -- a `` + * inside a CDATA section is ordinary character data, so it does not close the + * element; the lazy match stops there anyway and every declaration after it + * goes unscanned, in a file that is well-formed and renders. That hid a live + * `url(https://host/...)` fetch from findRemoteReferences, which is the gate + * that keeps a visitor's IP, User-Agent and Referer from reaching a host the + * diagram's author chose. + * + * CDATA sections are therefore consumed whole before `<` is given any + * meaning. A `'; assert.deepEqual(findRemoteReferences(svg), [ @@ -548,6 +548,58 @@ test('an empty inside a CDATA section does not end the ` inside a + // CDATA section is character data and does not close the element. A lazy + // `` match stops there anyway, so every + // declaration after it went unscanned in a file that is well-formed and + // renders -- a live remote fetch hidden from the gate that keeps a + // visitor's IP, User-Agent and Referer off a host the diagram chose. + const svg = + ''; + assert.deepEqual(findRemoteReferences(svg), [ + 'references a remote resource in a ` in the first. + const svg = + '' + + '' + + ''; + assert.deepEqual(findRemoteReferences(svg), [ + 'references a remote resource in a