Fix JSON parsing of unicode escapes
This commit is contained in:
parent
272c5ab0e9
commit
4fb675be2f
1 changed files with 13 additions and 5 deletions
|
@ -428,17 +428,25 @@ impl Parser {
|
||||||
while i < 4u {
|
while i < 4u {
|
||||||
match self.next_char() {
|
match self.next_char() {
|
||||||
'0' to '9' => {
|
'0' to '9' => {
|
||||||
n = n * 10u +
|
n = n * 16u + (self.ch as uint)
|
||||||
(self.ch as uint) - ('0' as uint);
|
- ('0' as uint);
|
||||||
}
|
},
|
||||||
_ => return self.error(~"invalid \\u escape")
|
'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;
|
i += 1u;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error out if we didn't parse 4 digits.
|
// Error out if we didn't parse 4 digits.
|
||||||
if i != 4u {
|
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);
|
str::push_char(res, n as char);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue