From 4fb675be2f42a828fb5a6570b9aad2c65f4598b9 Mon Sep 17 00:00:00 2001 From: Kevin Cantu Date: Thu, 30 Aug 2012 20:12:10 -0700 Subject: [PATCH] Fix JSON parsing of unicode escapes --- src/libstd/json.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/libstd/json.rs b/src/libstd/json.rs index aa986a281a1..c8f15d47469 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -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);