Permalink
Browse files

[less mode] Fix a few more unsafe method calls on .peek()

Issue #2028
  • Loading branch information...
1 parent 524159f commit b235f8d0e0418ceafa091281806a6d9c72d3d113 @marijnh marijnh committed Dec 5, 2013
Showing with 7 additions and 6 deletions.
  1. +7 −6 mode/less/less.js
View
@@ -71,7 +71,7 @@ CodeMirror.defineMode("less", function(config) {
if(stream.peek() === " ")stream.eatSpace();
if(stream.peek() === ")" || type === ":")return ret("number", "unit");//rgba(0,0,0,.25);
else if(stream.current().length >1){
- if(state.stack[state.stack.length-1] === "rule" && stream.peek().match(/{|,|\+|\(/) === null)return ret("number", "unit");
+ if(state.stack[state.stack.length-1] === "rule" && !stream.match(/^[{,+(]/, false)) return ret("number", "unit");
}
return ret("tag", "tag");
} else if (ch == "#") {
@@ -170,7 +170,7 @@ CodeMirror.defineMode("less", function(config) {
} else if(type == "compare" || type == "a" || type == "("){
return ret("string", "string");
} else if(type == "|" || stream.current() == "-" || type == "["){
- if(type == "|" && stream.peek().match(/\]|=|\~/) !== null)return ret("number", stream.current());
+ if (type == "|" && stream.match(/^[\]=~]/, false)) return ret("number", stream.current());
else if(type == "|" )return ret("tag", "tag");
else if(type == "["){
stream.eatWhile(/\w\-/);
@@ -201,7 +201,7 @@ CodeMirror.defineMode("less", function(config) {
//else if((type === ")" && state.stack[state.stack.length-1] === "rule") || (state.stack[state.stack.length-2] === "{" && state.stack[state.stack.length-1] === "rule" && type === "variable"))return ret(null, stream.current());
- else if(/\^|\$/.test(stream.current()) && stream.peek().match(/\~|=/) !== null)return ret("string", "string");//att^=val
+ else if (/\^|\$/.test(stream.current()) && stream.match(/^[~=]/, false)) return ret("string", "string");//att^=val
else if(type === "unit" && state.stack[state.stack.length-1] === "rule")return ret(null, "unit");
else if(type === "unit" && state.stack[state.stack.length-1] === ";")return ret(null, "unit");
@@ -210,12 +210,13 @@ CodeMirror.defineMode("less", function(config) {
//else if(type === "unit" && state.stack[state.stack.length-1] === "rule")return ret(null, stream.current());
else if((type === ";" || type === "}" || type === ",") && state.stack[state.stack.length-1] === ";")return ret("tag", stream.current());
- else if((type === ";" && stream.peek() !== undefined && stream.peek().match(/{|./) === null) || (type === ";" && stream.eatSpace() && stream.peek().match(/{|./) === null))return ret("variable", stream.current());
+ else if((type === ";" && stream.peek() !== undefined && !stream.match(/^[{\.]/, false)) ||
+ (type === ";" && stream.eatSpace() && !stream.match(/^[{\.]/))) return ret("variable", stream.current());
else if((type === "@media" && state.stack[state.stack.length-1] === "@media") || type === "@namespace")return ret("tag", stream.current());
else if(type === "{" && state.stack[state.stack.length-1] === ";" && stream.peek() === "{")return ret("tag", "tag");
else if((type === "{" || type === ":") && state.stack[state.stack.length-1] === ";")return ret(null, stream.current());
- else if((state.stack[state.stack.length-1] === "{" && stream.eatSpace() && stream.peek().match(/.|#/) === null) || type === "select-op" || (state.stack[state.stack.length-1] === "rule" && type === ",") )return ret("tag", "tag");
+ else if((state.stack[state.stack.length-1] === "{" && stream.eatSpace() && !stream.match(/^[\.#]/)) || type === "select-op" || (state.stack[state.stack.length-1] === "rule" && type === ",") )return ret("tag", "tag");
else if(type === "variable" && state.stack[state.stack.length-1] === "rule")return ret("tag", "tag");
else if((stream.eatSpace() && stream.peek() === "{") || stream.eol() || stream.peek() === "{")return ret("tag", "tag");
//this one messes up indentation
@@ -227,7 +228,7 @@ CodeMirror.defineMode("less", function(config) {
else if(stream.sol())return ret("tag", "tag");
else if((stream.eatSpace() && stream.peek() === "#") || stream.peek() === "#")return ret("tag", "tag");
else if(state.stack.length === 0)return ret("tag", "tag");
- else if(type === ";" && stream.peek() !== undefined && stream.peek().match(/^[.|\#]/g) !== null)return ret("tag", "tag");
+ else if(type === ";" && stream.peek() !== undefined && stream.match(/^[\.|#]/g)) return ret("tag", "tag");
else if(type === ":"){stream.eatSpace();return ret(null, stream.current());}

0 comments on commit b235f8d

Please sign in to comment.