1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Allow $ and _ at start of property identifiers

Fixes #1063
This commit is contained in:
Nick O'Leary 2016-11-21 21:36:18 +00:00
parent 071a04595a
commit 564902b886
3 changed files with 7 additions and 2 deletions

View File

@ -36,7 +36,7 @@
return false; return false;
} }
// Next char is a-z // Next char is a-z
if (!/[a-z0-9]/i.test(str[i+1])) { if (!/[a-z0-9\$\_]/i.test(str[i+1])) {
return false; return false;
} }
start = i+1; start = i+1;

View File

@ -161,7 +161,7 @@ function normalisePropertyExpression(str) {
throw new Error("Invalid property expression: unterminated expression"); throw new Error("Invalid property expression: unterminated expression");
} }
// Next char is a-z // Next char is a-z
if (!/[a-z0-9]/i.test(str[i+1])) { if (!/[a-z0-9\$\_]/i.test(str[i+1])) {
throw new Error("Invalid property expression: unexpected "+str[i+1]+" at position "+(i+1)); throw new Error("Invalid property expression: unexpected "+str[i+1]+" at position "+(i+1));
} }
start = i+1; start = i+1;

View File

@ -333,6 +333,11 @@ describe("red/util", function() {
it("pass a['a.b[0]'].c",function() { testABC("a['a.b[0]'].c",['a','a.b[0]','c']); }) it("pass a['a.b[0]'].c",function() { testABC("a['a.b[0]'].c",['a','a.b[0]','c']); })
it("pass a[0][0][0]",function() { testABC("a[0][0][0]",['a',0,0,0]); }) it("pass a[0][0][0]",function() { testABC("a[0][0][0]",['a',0,0,0]); })
it('pass a.$b.c',function() { testABC('a.$b.c',['a','$b','c']); })
it('pass a["$b"].c',function() { testABC('a["$b"].c',['a','$b','c']); })
it('pass a._b.c',function() { testABC('a._b.c',['a','_b','c']); })
it('pass a["_b"].c',function() { testABC('a["_b"].c',['a','_b','c']); })
it("fail a'b'.c",function() { testInvalid("a'b'.c"); }) it("fail a'b'.c",function() { testInvalid("a'b'.c"); })
it("fail a['b'.c",function() { testInvalid("a['b'.c"); }) it("fail a['b'.c",function() { testInvalid("a['b'.c"); })
it("fail a[]",function() { testInvalid("a[]"); }) it("fail a[]",function() { testInvalid("a[]"); })