Skip to content

Commit

Permalink
Prevent the user of non-breaking space and several other non-space wh…
Browse files Browse the repository at this point in the history
…itespace characters (PolymerLabs#4230)
  • Loading branch information
Cypher1 authored Dec 9, 2019
1 parent 1c8e255 commit a4cc0f8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/runtime/manifest-parser.peg
Original file line number Diff line number Diff line change
Expand Up @@ -1401,10 +1401,12 @@ dottedName "a name conforming to the rules of an android app name, per https://d
simpleName "a name starting with a letter and containing letters, digits and underscores"
= [a-zA-Z][a-zA-Z0-9_]* {return text();}
whiteSpace "one or more whitespace characters"
= " "+
= spaceChar+
spaceChar "a 'plain' space (use whiteSpace instead)"
= ' ' / ("\u00A0" / "\t" / "\f" / "\r" / "\v") {expected('space');}
eolWhiteSpace "a group of new lines (and optionally comments)"
= [ ]* !.
/ [ ]* '//' [^\n]* eolWhiteSpace
/ [ ]* eol eolWhiteSpace?
= spaceChar* !.
/ spaceChar* '//' [^\n]* eolWhiteSpace
/ spaceChar* eol eolWhiteSpace?
eol "a new line"
= "\r"? "\n" "\r"?
21 changes: 21 additions & 0 deletions src/runtime/tests/manifest-parser-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ describe('manifest parser', () => {
parse(`
recipe Recipe`);
});
it('fails to parse non-standard indentation (horizontal tab)', () => {
// Note: This is to protect against confusing whitespace issues caused by
// mixed tabs and spaces.
assert.throws(() => {
parse('\trecipe Recipe');
}, 'Expected space but "\\t" found.');
});
it('fails to parse non-standard indentation (vertical tab)', () => {
// Note: This is to protect against confusing whitespace issues caused by
// mixed tabs and spaces.
assert.throws(() => {
parse('\vrecipe Recipe');
}, 'Expected space but "\\x0B" found.');
});
it('fails to parse non-standard indentation (non-breaking space)', () => {
// Note: This is to protect against confusing whitespace issues caused by
// mixed tabs and spaces.
assert.throws(() => {
parse('\xA0recipe Recipe');
}, 'Expected space but "\xA0" found.');
});
it('parses recipes that map handles', () => {
parse(`
recipe Thing
Expand Down

0 comments on commit a4cc0f8

Please sign in to comment.