Escape vertical tab as "\v", not "\x0B"

See #441.
redux
David Majda 8 years ago
parent f36a667376
commit 9c04c94c85

@ -312,7 +312,7 @@ SingleEscapeCharacter
/ "n" { return "\n"; } / "n" { return "\n"; }
/ "r" { return "\r"; } / "r" { return "\r"; }
/ "t" { return "\t"; } / "t" { return "\t"; }
/ "v" { return "\x0B"; } // IE does not recognize "\v". / "v" { return "\v"; }
NonEscapeCharacter NonEscapeCharacter
= !(EscapeCharacter / LineTerminator) SourceCharacter { return text(); } = !(EscapeCharacter / LineTerminator) SourceCharacter { return text(); }

@ -12,8 +12,6 @@ var js = {
* may appear in the form of an escape sequence. * may appear in the form of an escape sequence.
* *
* For portability, we also escape all control and non-ASCII characters. * For portability, we also escape all control and non-ASCII characters.
* Note that the "\v" escape sequence is not used because IE does not like
* it.
*/ */
return s return s
.replace(/\\/g, '\\\\') // backslash .replace(/\\/g, '\\\\') // backslash
@ -22,6 +20,7 @@ var js = {
.replace(/\x08/g, '\\b') // backspace .replace(/\x08/g, '\\b') // backspace
.replace(/\t/g, '\\t') // horizontal tab .replace(/\t/g, '\\t') // horizontal tab
.replace(/\n/g, '\\n') // line feed .replace(/\n/g, '\\n') // line feed
.replace(/\v/g, '\\v') // vertical tab
.replace(/\f/g, '\\f') // form feed .replace(/\f/g, '\\f') // form feed
.replace(/\r/g, '\\r') // carriage return .replace(/\r/g, '\\r') // carriage return
.replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
@ -45,7 +44,7 @@ var js = {
.replace(/\0/g, '\\0') // null .replace(/\0/g, '\\0') // null
.replace(/\t/g, '\\t') // horizontal tab .replace(/\t/g, '\\t') // horizontal tab
.replace(/\n/g, '\\n') // line feed .replace(/\n/g, '\\n') // line feed
.replace(/\v/g, '\\x0B') // vertical tab .replace(/\v/g, '\\v') // vertical tab
.replace(/\f/g, '\\f') // form feed .replace(/\f/g, '\\f') // form feed
.replace(/\r/g, '\\r') // carriage return .replace(/\r/g, '\\r') // carriage return
.replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); })

@ -260,8 +260,8 @@ function peg$parse(input, options) {
peg$c35 = peg$otherExpectation("whitespace"), peg$c35 = peg$otherExpectation("whitespace"),
peg$c36 = "\t", peg$c36 = "\t",
peg$c37 = peg$literalExpectation("\t", false), peg$c37 = peg$literalExpectation("\t", false),
peg$c38 = "\x0B", peg$c38 = "\v",
peg$c39 = peg$literalExpectation("\x0B", false), peg$c39 = peg$literalExpectation("\v", false),
peg$c40 = "\f", peg$c40 = "\f",
peg$c41 = peg$literalExpectation("\f", false), peg$c41 = peg$literalExpectation("\f", false),
peg$c42 = " ", peg$c42 = " ",
@ -368,7 +368,7 @@ function peg$parse(input, options) {
peg$c120 = function() { return "\t"; }, peg$c120 = function() { return "\t"; },
peg$c121 = "v", peg$c121 = "v",
peg$c122 = peg$literalExpectation("v", false), peg$c122 = peg$literalExpectation("v", false),
peg$c123 = function() { return "\x0B"; }, peg$c123 = function() { return "\v"; },
peg$c124 = "x", peg$c124 = "x",
peg$c125 = peg$literalExpectation("x", false), peg$c125 = peg$literalExpectation("x", false),
peg$c126 = "u", peg$c126 = "u",

@ -384,7 +384,7 @@ describe("PEG.js grammar parser", function() {
/* Canonical WhiteSpace is " ". */ /* Canonical WhiteSpace is " ". */
it("parses WhiteSpace", function() { it("parses WhiteSpace", function() {
expect('start =\t"abcd"' ).toParseAs(trivialGrammar); expect('start =\t"abcd"' ).toParseAs(trivialGrammar);
expect('start =\x0B"abcd"' ).toParseAs(trivialGrammar); // no "\v" in IE expect('start =\v"abcd"' ).toParseAs(trivialGrammar);
expect('start =\f"abcd"' ).toParseAs(trivialGrammar); expect('start =\f"abcd"' ).toParseAs(trivialGrammar);
expect('start = "abcd"' ).toParseAs(trivialGrammar); expect('start = "abcd"' ).toParseAs(trivialGrammar);
expect('start =\u00A0"abcd"').toParseAs(trivialGrammar); expect('start =\u00A0"abcd"').toParseAs(trivialGrammar);
@ -596,7 +596,7 @@ describe("PEG.js grammar parser", function() {
expect('start = "\\n"' ).toParseAs(literalGrammar("\n", false)); expect('start = "\\n"' ).toParseAs(literalGrammar("\n", false));
expect('start = "\\r"' ).toParseAs(literalGrammar("\r", false)); expect('start = "\\r"' ).toParseAs(literalGrammar("\r", false));
expect('start = "\\t"' ).toParseAs(literalGrammar("\t", false)); expect('start = "\\t"' ).toParseAs(literalGrammar("\t", false));
expect('start = "\\v"' ).toParseAs(literalGrammar("\x0B", false)); // no "\v" in IE expect('start = "\\v"' ).toParseAs(literalGrammar("\v", false));
}); });
/* Canonical NonEscapeCharacter is "a". */ /* Canonical NonEscapeCharacter is "a". */

@ -409,7 +409,7 @@ SingleEscapeCharacter
/ "n" { return "\n"; } / "n" { return "\n"; }
/ "r" { return "\r"; } / "r" { return "\r"; }
/ "t" { return "\t"; } / "t" { return "\t"; }
/ "v" { return "\x0B"; } // IE does not recognize "\v". / "v" { return "\v"; }
NonEscapeCharacter NonEscapeCharacter
= !(EscapeCharacter / LineTerminator) SourceCharacter { return text(); } = !(EscapeCharacter / LineTerminator) SourceCharacter { return text(); }

Loading…
Cancel
Save