Fix JSON parsing of unicode escapes

This commit is contained in:
Kevin Cantu 2012-08-30 20:12:10 -07:00 committed by Erick Tryzelaar
parent 272c5ab0e9
commit 4fb675be2f

View File

@ -428,17 +428,25 @@ impl Parser {
while i < 4u {
match self.next_char() {
'0' to '9' => {
n = n * 10u +
(self.ch as uint) - ('0' as uint);
}
_ => return self.error(~"invalid \\u escape")
n = n * 16u + (self.ch as uint)
- ('0' as uint);
},
'a' | 'A' => n = n * 16u + 10u,
'b' | 'B' => n = n * 16u + 11u,
'c' | 'C' => n = n * 16u + 12u,
'd' | 'D' => n = n * 16u + 13u,
'e' | 'E' => n = n * 16u + 14u,
'f' | 'F' => n = n * 16u + 15u,
_ => return self.error(
~"invalid \\u escape (unrecognized hex)")
}
i += 1u;
}
// Error out if we didn't parse 4 digits.
if i != 4u {
return self.error(~"invalid \\u escape");
return self.error(
~"invalid \\u escape (not four digits)");
}
str::push_char(res, n as char);