Skip to content

Commit

Permalink
Merge pull request #64 from rwjblue/fix-issue-with-attribute-plus-sel…
Browse files Browse the repository at this point in the history
…f-closing

Fix regression with unquoted attributes without space before self-closing tag.
  • Loading branch information
rwjblue committed Jun 11, 2018
2 parents 04c6ba3 + 672643e commit 1039b74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/evented-tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ export default class EventedTokenizer {
this.consume();
this.transitionTo(TokenizerState.beforeAttributeName);
} else if (char === '/') {
this.delegate.finishAttributeValue();
this.consume();
this.transitionTo(TokenizerState.selfClosingStartTag);
} else if (char === '&') {
Expand Down
24 changes: 10 additions & 14 deletions src/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ export default class Tokenizer implements TokenizerDelegate {
private startColumn = 0;
private tokenizer: EventedTokenizer;
private tokens: Token[] = [];
private _currentAttribute?: Attribute;

constructor(
entityParser: EntityParser,
private options: TokenizerOptions = {}
) {
this.tokenizer = new EventedTokenizer(this, entityParser);
this._currentAttribute = undefined;
}

tokenize(input: string) {
Expand Down Expand Up @@ -75,15 +77,7 @@ export default class Tokenizer implements TokenizerDelegate {
}

currentAttribute() {
let { attributes } = this.current(TokenType.StartTag);
if (attributes.length === 0) {
throw new Error('expected to have an attribute started');
}
return attributes[attributes.length - 1];
}

pushAttribute(attribute: Attribute) {
this.current(TokenType.StartTag).attributes.push(attribute);
return this._currentAttribute;
}

addLocInfo() {
Expand Down Expand Up @@ -173,22 +167,24 @@ export default class Tokenizer implements TokenizerDelegate {
// Tags - attributes

beginAttribute() {
this.pushAttribute(['', '', false]);
this._currentAttribute = ['', '', false];
}

appendToAttributeName(char: string) {
this.currentAttribute()[0] += char;
this.currentAttribute()![0] += char;
}

beginAttributeValue(isQuoted: boolean) {
this.currentAttribute()[2] = isQuoted;
this.currentAttribute()![2] = isQuoted;
}

appendToAttributeValue(char: string) {
this.currentAttribute()[1] += char;
this.currentAttribute()![1] += char;
}

finishAttributeValue() {}
finishAttributeValue() {
this.current(TokenType.StartTag).attributes.push(this._currentAttribute!);
}

reportSyntaxError(message: string) {
this.current().syntaxError = message;
Expand Down

0 comments on commit 1039b74

Please sign in to comment.