Adjusting grammar to match \c escape "correctly"

\c followed by something other than a-z leads to inconsistent behavior
across browsers. Most will treat it as a series of literals (/\c#/ will
match the string "\\c#" for example)
This commit is contained in:
Jeff Avallone 2014-12-22 15:00:38 -05:00
parent 101b457260
commit 580af045d6

View File

@ -22,20 +22,20 @@ grammar JavascriptRegexp
/ charset_literal <Literal>
charset_escape <- "\\" esc:(
code:[bdDfnrsStvwW] arg:""?
/ code:"c" arg:.
/ code:"c" arg:[a-zA-Z]
/ code:"0" arg:[0-7]+
/ code:"x" arg:( [0-9a-fA-F] [0-9a-fA-F] )
/ code:"u" arg:( [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] )
/ code:"0" arg:""? )
charset_literal <- ( ""? literal:[^\\\]] ) / ( "\\" literal:. )
charset_literal <- ( ""? literal:[^\\\]] ) / ( literal:"\\" &"c" ) / ( "\\" literal:. )
terminal <- "." <AnyCharacter>
/ escape <Escape>
/ literal <Literal>
escape <- "\\" esc:(
code:[bBdDfnrsStvwW1-9] arg:""?
/ code:"c" arg:.
/ code:"c" arg:[a-zA-Z]
/ code:"0" arg:[0-7]+
/ code:"x" arg:( [0-9a-fA-F] [0-9a-fA-F] )
/ code:"u" arg:( [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] )
/ code:"0" arg:""? )
literal <- ( ""? literal:[^|\\/.\[\(\)?+*$^] ) / ( "\\" literal:. )
literal <- ( ""? literal:[^|\\/.\[\(\)?+*$^] ) / ( literal:"\\" &"c" ) / ( "\\" literal:. )