mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
fixed negative numbers in Json
This commit is contained in:
parent
a27198d52e
commit
9c8b1800b9
2 changed files with 6 additions and 2 deletions
|
|
@ -32,7 +32,7 @@ function lex(text, parseStringsForObjects){
|
|||
index = 0,
|
||||
json = [],
|
||||
ch,
|
||||
lastCh = ','; // can start regexp
|
||||
lastCh = ':'; // can start regexp
|
||||
|
||||
while (index < text.length) {
|
||||
ch = text.charAt(index);
|
||||
|
|
@ -64,7 +64,7 @@ function lex(text, parseStringsForObjects){
|
|||
tokens.push({index:index, text:ch2, fn:fn2});
|
||||
index += 2;
|
||||
} else if (fn) {
|
||||
tokens.push({index:index, text:ch, fn:fn});
|
||||
tokens.push({index:index, text:ch, fn:fn, json: was('[,:') && is('+-')});
|
||||
index += 1;
|
||||
} else {
|
||||
throw "Lexer Error: Unexpected next character [" +
|
||||
|
|
|
|||
|
|
@ -100,6 +100,10 @@ describe('json', function(){
|
|||
expect(fromJson("{value:2.55, name:'misko'}")).toEqual({value:2.55, name:'misko'});
|
||||
});
|
||||
|
||||
it('should parse negative / possitve numbers', function() {
|
||||
expect(fromJson("{neg:-2.55, pos:+.3, a:[-2, +.1, -.2, +.3]}")).toEqual({neg:-2.55, pos:+.3, a:[-2, +.1, -.2, +.3]});
|
||||
});
|
||||
|
||||
describe('security', function(){
|
||||
it('should not allow naked expressions', function(){
|
||||
expect(function(){fromJson('1+2');}).toThrow("Did not understand '+2' while evaluating '1+2'.");
|
||||
|
|
|
|||
Loading…
Reference in a new issue