diff options
| author | Colomban Wendling <ban@herbesfolles.org> | 2012-12-30 20:28:05 +0100 | 
|---|---|---|
| committer | Colomban Wendling <ban@herbesfolles.org> | 2012-12-30 20:28:05 +0100 | 
| commit | 650e2266b902a5d3029753b4575a5fa01ea12db2 (patch) | |
| tree | 75299c8c43922dce4c5958c2a20205ae04278449 | |
| parent | 1d26bd892cb1f9dbeacd9538413601758a0051a2 (diff) | |
| download | scintilla-mirror-650e2266b902a5d3029753b4575a5fa01ea12db2.tar.gz | |
Fix parsing of JavaScript regular expressions containing a delimiter in a range
Regular expression "/[/]/" is valid, the second "/" being escaped by the
character range ("[]").  Also, escape any \-prefixed character, including
"[" and "]".
| -rw-r--r-- | lexers/LexCPP.cxx | 17 | 
1 files changed, 11 insertions, 6 deletions
| diff --git a/lexers/LexCPP.cxx b/lexers/LexCPP.cxx index 834c273fa..87482176d 100644 --- a/lexers/LexCPP.cxx +++ b/lexers/LexCPP.cxx @@ -471,6 +471,7 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle,  	bool continuationLine = false;  	bool isIncludePreprocessor = false;  	bool isStringInPreprocessor = false; +	bool inRERange = false;  	int lineCurrent = styler.GetLine(startPos);  	if ((MaskActive(initStyle) == SCE_C_PREPROCESSOR) || @@ -544,6 +545,7 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle,  			visibleChars = 0;  			lastWordWasUUID = false;  			isIncludePreprocessor = false; +			inRERange = false;  			if (preproc.IsInactive()) {  				activitySet = activeFlag;  				sc.SetState(sc.state | activitySet); @@ -748,16 +750,18 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle,  			case SCE_C_REGEX:  				if (sc.atLineStart) {  					sc.SetState(SCE_C_DEFAULT|activitySet); -				} else if (sc.ch == '/') { +				} else if (! inRERange && sc.ch == '/') {  					sc.Forward();  					while ((sc.ch < 0x80) && islower(sc.ch))  						sc.Forward();    // gobble regex flags  					sc.SetState(SCE_C_DEFAULT|activitySet); -				} else if (sc.ch == '\\') { -					// Gobble up the quoted character -					if (sc.chNext == '\\' || sc.chNext == '/') { -						sc.Forward(); -					} +				} else if (sc.ch == '\\' && (sc.chNext != '\n' && sc.chNext != '\r')) { +					// Gobble up the escaped character +					sc.Forward(); +				} else if (sc.ch == '[') { +					inRERange = true; +				} else if (sc.ch == ']') { +					inRERange = false;  				}  				break;  			case SCE_C_STRINGEOL: @@ -838,6 +842,7 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle,  				   && (!setCouldBePostOp.Contains(chPrevNonWhite)  				       || !FollowsPostfixOperator(sc, styler))) {  				sc.SetState(SCE_C_REGEX|activitySet);	// JavaScript's RegEx +				inRERange = false;  			} else if (sc.ch == '\"') {  				if (sc.chPrev == 'R') {  					styler.Flush(); | 
