Fix broken number parsing in fromJSON
The call to tmp_number.append had its arguments mixed up. Also, JSON does not allow a trailing "," after array/object members.
This commit is contained in:
		
							parent
							
								
									eb62e23f14
								
							
						
					
					
						commit
						e03d6e0998
					
				
					 2 changed files with 4 additions and 5 deletions
				
			
		|  | @ -113,14 +113,13 @@ static void parseJSON(EvalState & state, const char * & s, Value & v) | ||||||
|         while (isdigit(*s) || *s == '-' || *s == '.' || *s == 'e' || *s == 'E') { |         while (isdigit(*s) || *s == '-' || *s == '.' || *s == 'e' || *s == 'E') { | ||||||
|             if (*s == '.' || *s == 'e' || *s == 'E') |             if (*s == '.' || *s == 'e' || *s == 'E') | ||||||
|                 number_type = tFloat; |                 number_type = tFloat; | ||||||
|             tmp_number.append(*s++, 1); |             tmp_number += *s++; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (number_type == tFloat) { |         if (number_type == tFloat) | ||||||
|             mkFloat(v, stod(tmp_number)); |             mkFloat(v, stod(tmp_number)); | ||||||
|         } else { |         else | ||||||
|             mkInt(v, stoi(tmp_number)); |             mkInt(v, stoi(tmp_number)); | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     else if (strncmp(s, "true", 4) == 0) { |     else if (strncmp(s, "true", 4) == 0) { | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ builtins.fromJSON | ||||||
|           "Animated" : false, |           "Animated" : false, | ||||||
|           "IDs": [116, 943, 234, 38793, true  ,false,null, -100], |           "IDs": [116, 943, 234, 38793, true  ,false,null, -100], | ||||||
|           "Latitude":  37.7668, |           "Latitude":  37.7668, | ||||||
|           "Longitude": -122.3959, |           "Longitude": -122.3959 | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   '' |   '' | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue