simple-html-tokenizer
Advanced tools
Comparing version
@@ -62,3 +62,3 @@ /** | ||
var char = this.peek(); | ||
if (char === '<') { | ||
if (char === '<' && !this.isIgnoredEndTag()) { | ||
this.transitionTo("tagOpen" /* tagOpen */); | ||
@@ -81,3 +81,4 @@ this.markTagStart(); | ||
var char = this.peek(); | ||
if (char === '<') { | ||
var tag = this.tagNameBuffer.toLowerCase(); | ||
if (char === '<' && !this.isIgnoredEndTag()) { | ||
this.delegate.finishData(); | ||
@@ -88,3 +89,3 @@ this.transitionTo("tagOpen" /* tagOpen */); | ||
} | ||
else if (char === '&') { | ||
else if (char === '&' && tag !== 'script' && tag !== 'style') { | ||
this.consume(); | ||
@@ -115,3 +116,3 @@ this.delegate.appendToData(this.consumeCharRef() || '&'); | ||
var char = this.consume(); | ||
if (char === '-' && this.input.charAt(this.index) === '-') { | ||
if (char === '-' && this.peek() === '-') { | ||
this.consume(); | ||
@@ -196,2 +197,21 @@ this.transitionTo("commentStart" /* commentStart */); | ||
}, | ||
endTagName: function () { | ||
var char = this.consume(); | ||
if (isSpace(char)) { | ||
this.transitionTo("beforeAttributeName" /* beforeAttributeName */); | ||
this.tagNameBuffer = ''; | ||
} | ||
else if (char === '/') { | ||
this.transitionTo("selfClosingStartTag" /* selfClosingStartTag */); | ||
this.tagNameBuffer = ''; | ||
} | ||
else if (char === '>') { | ||
this.delegate.finishTag(); | ||
this.transitionTo("beforeData" /* beforeData */); | ||
this.tagNameBuffer = ''; | ||
} | ||
else { | ||
this.appendToTagName(char); | ||
} | ||
}, | ||
beforeAttributeName: function () { | ||
@@ -405,3 +425,3 @@ var char = this.peek(); | ||
if (char === '@' || char === ':' || isAlpha(char)) { | ||
this.transitionTo("tagName" /* tagName */); | ||
this.transitionTo("endTagName" /* endTagName */); | ||
this.tagNameBuffer = ''; | ||
@@ -418,2 +438,3 @@ this.delegate.beginEndTag(); | ||
this.input = ''; | ||
this.tagNameBuffer = ''; | ||
this.index = 0; | ||
@@ -494,2 +515,8 @@ this.line = 1; | ||
}; | ||
EventedTokenizer.prototype.isIgnoredEndTag = function () { | ||
var tag = this.tagNameBuffer.toLowerCase(); | ||
return (tag === 'title' && this.input.substring(this.index, this.index + 8) !== '</title>') || | ||
(tag === 'style' && this.input.substring(this.index, this.index + 8) !== '</style>') || | ||
(tag === 'script' && this.input.substring(this.index, this.index + 9) !== '</script>'); | ||
}; | ||
return EventedTokenizer; | ||
@@ -496,0 +523,0 @@ }()); |
@@ -68,3 +68,3 @@ (function (global, factory) { | ||
var char = this.peek(); | ||
if (char === '<') { | ||
if (char === '<' && !this.isIgnoredEndTag()) { | ||
this.transitionTo("tagOpen" /* tagOpen */); | ||
@@ -87,3 +87,4 @@ this.markTagStart(); | ||
var char = this.peek(); | ||
if (char === '<') { | ||
var tag = this.tagNameBuffer.toLowerCase(); | ||
if (char === '<' && !this.isIgnoredEndTag()) { | ||
this.delegate.finishData(); | ||
@@ -94,3 +95,3 @@ this.transitionTo("tagOpen" /* tagOpen */); | ||
} | ||
else if (char === '&') { | ||
else if (char === '&' && tag !== 'script' && tag !== 'style') { | ||
this.consume(); | ||
@@ -121,3 +122,3 @@ this.delegate.appendToData(this.consumeCharRef() || '&'); | ||
var char = this.consume(); | ||
if (char === '-' && this.input.charAt(this.index) === '-') { | ||
if (char === '-' && this.peek() === '-') { | ||
this.consume(); | ||
@@ -202,2 +203,21 @@ this.transitionTo("commentStart" /* commentStart */); | ||
}, | ||
endTagName: function () { | ||
var char = this.consume(); | ||
if (isSpace(char)) { | ||
this.transitionTo("beforeAttributeName" /* beforeAttributeName */); | ||
this.tagNameBuffer = ''; | ||
} | ||
else if (char === '/') { | ||
this.transitionTo("selfClosingStartTag" /* selfClosingStartTag */); | ||
this.tagNameBuffer = ''; | ||
} | ||
else if (char === '>') { | ||
this.delegate.finishTag(); | ||
this.transitionTo("beforeData" /* beforeData */); | ||
this.tagNameBuffer = ''; | ||
} | ||
else { | ||
this.appendToTagName(char); | ||
} | ||
}, | ||
beforeAttributeName: function () { | ||
@@ -411,3 +431,3 @@ var char = this.peek(); | ||
if (char === '@' || char === ':' || isAlpha(char)) { | ||
this.transitionTo("tagName" /* tagName */); | ||
this.transitionTo("endTagName" /* endTagName */); | ||
this.tagNameBuffer = ''; | ||
@@ -424,2 +444,3 @@ this.delegate.beginEndTag(); | ||
this.input = ''; | ||
this.tagNameBuffer = ''; | ||
this.index = 0; | ||
@@ -500,2 +521,8 @@ this.line = 1; | ||
}; | ||
EventedTokenizer.prototype.isIgnoredEndTag = function () { | ||
var tag = this.tagNameBuffer.toLowerCase(); | ||
return (tag === 'title' && this.input.substring(this.index, this.index + 8) !== '</title>') || | ||
(tag === 'style' && this.input.substring(this.index, this.index + 8) !== '</style>') || | ||
(tag === 'script' && this.input.substring(this.index, this.index + 9) !== '</script>'); | ||
}; | ||
return EventedTokenizer; | ||
@@ -502,0 +529,0 @@ }()); |
@@ -23,2 +23,3 @@ import { EntityParser, TokenizerDelegate, TokenizerState } from './types'; | ||
private appendToTagName(char); | ||
private isIgnoredEndTag(); | ||
states: { | ||
@@ -25,0 +26,0 @@ [k in TokenizerState]?: (this: EventedTokenizer) => void; |
@@ -15,2 +15,3 @@ /** | ||
tagName = "tagName", | ||
endTagName = "endTagName", | ||
rcdataLessThanSign = "rcdataLessThanSign", | ||
@@ -17,0 +18,0 @@ rcdataEndTagOpen = "rcdataEndTagOpen", |
{ | ||
"name": "simple-html-tokenizer", | ||
"version": "0.5.7", | ||
"version": "0.5.8", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Simple HTML Tokenizer is a lightweight JavaScript library that can be used to tokenize the kind of HTML normally found in templates.", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
401845
1.83%3925
1.45%0
-100%