Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ const Tokenizer = require(join(
const IN_TAG_NAME = 3

class ForeignTokenizer extends Tokenizer {
// htmlparser2 ends a raw-text end tag on ">" or whitespace only. The HTML
// tokenizer also ends it on "/", so "</script/" (and the same for style,
// title, textarea, and xmp) swallows every later tag until a canonical
// end tag. Treat the solidus as whitespace; the closing-tag state then
// finishes the tag at the next ">".
stateInSpecialTag (char) {
if (this.sequenceIndex === this.currentSequence.length && char === 47) {
return super.stateInSpecialTag(32)
}
return super.stateInSpecialTag(char)
}

stateBeforeSpecialS (char) {
if (this.cbs.foreignContext[0] === true) {
this.state = IN_TAG_NAME
Expand Down
32 changes: 32 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,38 @@ test('annotation-xml with an html encoding keeps the script open', t => {
}
})

test('a raw-text end tag may end with a solidus', t => {
t.deepEqual(
parseIframe('<script src="/a.js"></script/><script src="/b.js"></script>'),
[{ src: '/a.js' }, { src: '/b.js' }]
)
t.deepEqual(
parseIframe('<script src="/a.js"></SCRIPT/><script src="/b.js"></script>'),
[{ src: '/a.js' }, { src: '/b.js' }]
)
t.deepEqual(
parseIframe(
'<div><script src="/a.js"></script/foo></div><script src="/b.js"></script>'
),
[{ src: '/a.js' }, { src: '/b.js' }]
)
t.deepEqual(
parseIframe(
'<script src="/a.js">var x="</script/><script src=\'/evil.js\'>"</script><script src="/b.js"></script>'
),
[{ src: '/a.js' }, { src: '/evil.js' }, { src: '/b.js' }]
)
t.deepEqual(parseIframe('<style></style/><script src="/b.js"></script>'), [
{ src: '/b.js' }
])
t.deepEqual(
parseIframe(
'<script src="/a.js"></scripting><script src="/b.js"></script>'
),
[{ src: '/a.js' }]
)
})

test('a script end tag may have whitespace before >', t => {
for (const gap of [' ', '\n', '\t', '\r', '\f']) {
t.deepEqual(
Expand Down
Loading