Skip to content
Browse files

* Fix JSON unicode handling (see http://pocoproject.org/forum/viewtop…

  • Loading branch information...
1 parent 79838aa commit 3a2116233bbecbce53d5266bd5c5727bea0bbd2a @RangelReale committed Dec 28, 2012
Showing with 16 additions and 10 deletions.
  1. +16 −10 JSON/src/Parser.cpp
View
26 JSON/src/Parser.cpp
@@ -38,6 +38,7 @@
#include "Poco/JSON/JSONException.h"
#include "Poco/Ascii.h"
#include "Poco/Token.h"
+#include "Poco/UnicodeConverter.h"
#undef min
#undef max
#include <limits>
@@ -140,28 +141,28 @@ class StringToken: public Token
switch(c)
{
case '"' :
- c = '"';
+ _value += '"';
break;
case '\\' :
- c = '\\';
+ _value += '\\';
break;
case '/' :
- c = '/';
+ _value += '/';
break;
case 'b' :
- c = '\b';
+ _value += '\b';
break;
case 'f' :
- c = '\f';
+ _value += '\f';
break;
case 'n' :
- c = '\n';
+ _value += '\n';
break;
case 'r' :
- c = '\r';
+ _value += '\r';
break;
case 't' :
- c = '\t';
+ _value += '\t';
break;
case 'u' : // Unicode
{
@@ -196,16 +197,21 @@ class StringToken: public Token
{
throw JSONException("Invalid unicode");
}
- c = unicode;
+ //unicode to utf8
+ std::string utf8;
+ UnicodeConverter::toUTF8((const UTF32Char*)&unicode,1,utf8);
+ _value += utf8;
+
break;
}
default:
{
throw JSONException(format("Invalid escape '%c' character used", (char) c));
}
}
+ }else{
+ _value += c;
}
- _value += c;
c = istr.get();
}

1 comment on commit 3a21162

@aleks-f

Please add a test case for this change and verify/confirm that it does not break any existing unit tests.

Please sign in to comment.
Something went wrong with that request. Please try again.