@@ -122,15 +122,13 @@ void yajl_string_decode(yajl_buf buf, const unsigned char * str,
122122 props -> has_ansi = 0 ;
123123 props -> line_feeds = 0 ;
124124 while (end < len ) {
125- if (str [end ] == '\x1b' ) {
126- props -> has_ansi = 1 ;
127- end ++ ;
128- } else if (str [end ] == '/' || str [end ] == '#' || str [end ] == '~' ) {
125+ if (str [end ] == '/' || str [end ] == '#' || str [end ] == '~' ) {
129126 props -> ptr_escapes += 1 ;
130127 end ++ ;
131128 } else if (str [end ] == '\\' ) {
132129 char utf8Buf [5 ];
133130 const char * unescaped = "?" ;
131+ unsigned int unescapedLen = 1 ;
134132 yajl_buf_append (buf , str + beg , end - beg );
135133 switch (str [++ end ]) {
136134 case 'r' : unescaped = "\r" ; break ;
@@ -157,7 +155,6 @@ void yajl_string_decode(yajl_buf buf, const unsigned char * str,
157155 | (surrogate & 0x3FF ));
158156 end += 5 ;
159157 } else {
160- unescaped = "?" ;
161158 break ;
162159 }
163160 } else if (codepoint == 0x1b ) {
@@ -168,6 +165,10 @@ void yajl_string_decode(yajl_buf buf, const unsigned char * str,
168165
169166 Utf32toUtf8 (codepoint , utf8Buf );
170167 unescaped = utf8Buf ;
168+ if (codepoint < 0x80 ) unescapedLen = 1 ;
169+ else if (codepoint < 0x800 ) unescapedLen = 2 ;
170+ else if (codepoint < 0x10000 ) unescapedLen = 3 ;
171+ else unescapedLen = 4 ;
171172
172173 if (codepoint == 0 ) {
173174 yajl_buf_append (buf , unescaped , 1 );
@@ -180,7 +181,7 @@ void yajl_string_decode(yajl_buf buf, const unsigned char * str,
180181 default :
181182 assert ("this should never happen" == NULL );
182183 }
183- yajl_buf_append (buf , unescaped , ( unsigned int ) strlen ( unescaped ) );
184+ yajl_buf_append (buf , unescaped , unescapedLen );
184185 beg = ++ end ;
185186 } else {
186187 end ++ ;
0 commit comments