10000 extmod, ujson: Add \uxxxx parsing in json strings. · comfuture/micropython@df1e92b · GitHub
[go: up one dir, main page]

Skip to content

Commit df1e92b

Browse files
committed
extmod, ujson: Add \uxxxx parsing in json strings.
1 parent fa2f1f7 commit df1e92b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

extmod/modujson.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) {
100100
break;
101101
case '"':
102102
vstr_reset(&vstr);
103-
for (s++; s < top && *s != '"'; s++) {
103+
for (s++; s < top && *s != '"';) {
104104
byte c = *s;
105105
if (c == '\\') {
106106
s++;
@@ -111,10 +111,24 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) {
111111
case 'n': c = 0x0a; break;
112112
case 'r': c = 0x0d; break;
113113
case 't': c = 0x09; break;
114-
case 'u': if (s + 4 >= top) { goto fail; } else { assert(0); } //vstr_add_char(&vstr, s[0]
114+
case 'u': {
115+
if (s + 4 >= top) { goto fail; }
116+
mp_uint_t num = 0;
117+
for (int i = 0; i < 4; i++) {
118+
c = (*++s | 0x20) - '0';
119+
if (c > 9) {
120+
c -= ('a' - ('9' + 1));
121+
}
122+
num = (num << 4) | c;
123+
}
124+
vstr_add_char(&vstr, num);
125+
goto str_cont;
126+
}
115127
}
116128
}
117129
vstr_add_byte(&vstr, c);
130+
str_cont:
131+
s++;
118132
}
119133
if (s == top) {
120134
goto fail;

0 commit comments

Comments
 (0)
0