Skip to content

Commit

Permalink
fix(tokenizer): Properly handle CR when peeking (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Oct 30, 2022
1 parent bb0129f commit e6f304c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/parse5/lib/parser/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ describe('parser', () => {
expect(doctype).toHaveProperty('systemId', '');
});

it('Regression - CRLF inside </noscript> (GH-710)', () => {
const onParseError = jest.fn();
parse('<!doctype html><noscript>foo</noscript\r\n>', { onParseError });

expect(onParseError).not.toHaveBeenCalled();
});

describe('Tree adapters', () => {
it('should support onItemPush and onItemPop', () => {
const onItemPush = jest.fn();
Expand Down
4 changes: 3 additions & 1 deletion packages/parse5/lib/tokenizer/preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ export class Preprocessor {
return $.EOF;
}

return this.html.charCodeAt(pos);
const code = this.html.charCodeAt(pos);

return code === $.CARRIAGE_RETURN ? $.LINE_FEED : code;
}

public advance(): number {
Expand Down

0 comments on commit e6f304c

Please sign in to comment.