Skip to content

Commit 7ffcb8f

Browse files
committed
Fixing bug with handling JSON unicode escape sequences when parsing utf-8.
1 parent f0c5d7c commit 7ffcb8f

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

Release/include/cpprest/asyncrt_utils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/***
22
* ==++==
33
*
4-
* Copyright (c) Microsoft Corporation. All rights reserved.
4+
* Copyright (c) Microsoft Corporation. All rights reserved.
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,7 +30,7 @@
3030
#if defined(_MSC_VER) && (_MSC_VER >= 1800)
3131
#include <ppltasks.h>
3232
namespace pplx = Concurrency;
33-
#else
33+
#else
3434
#include "pplx/pplxtasks.h"
3535
#endif
3636

Release/src/json/json_parsing.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ class JSON_Parser
152152
virtual bool CompleteComment(Token &token);
153153
virtual bool CompleteStringLiteral(Token &token);
154154
bool handle_unescape_char(Token &token);
155-
155+
void convert_append_unicode_code_unit(Token &token, char16_t value);
156+
156157
private:
157158

158159
bool CompleteNumberLiteral(CharType first, Token &token);
@@ -750,15 +751,28 @@ inline bool JSON_Parser<CharType>::handle_unescape_char(Token &token)
750751
}
751752

752753
// Construct the character based on the decoded number
753-
ch = static_cast<CharType>(decoded & 0xFFFF);
754-
token.string_val.push_back(ch);
754+
convert_append_unicode_code_unit(token, static_cast<char16_t>(decoded));
755+
755756
return true;
756757
}
757758
default:
758759
return false;
759760
}
760761
}
761762

763+
template <typename CharType>
764+
inline void JSON_Parser<CharType>::convert_append_unicode_code_unit(Token &token, char16_t value)
765+
{
766+
token.string_val.push_back(value);
767+
}
768+
769+
template <>
770+
inline void JSON_Parser<char>::convert_append_unicode_code_unit(Token &token, char16_t value)
771+
{
772+
utf16string utf16(reinterpret_cast<utf16char *>(&value), 1);
773+
token.string_val.append(::utility::conversions::utf16_to_utf8(utf16));
774+
}
775+
762776
template <typename CharType>
763777
bool JSON_Parser<CharType>::CompleteStringLiteral(Token &token)
764778
{

0 commit comments

Comments
 (0)