Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
a1909a94
Unverified
Commit
a1909a94
authored
Feb 13, 2018
by
Milo Yip
Committed by
GitHub
Feb 13, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1179 from Tencent/issue1153_rawvalueencoding
Add transcoding/validation to Writer::RawValue()
parents
e2d0437a
96698762
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
3 deletions
+45
-3
writer.h
include/rapidjson/writer.h
+8
-3
writertest.cpp
test/unittest/writertest.cpp
+37
-0
No files found.
include/rapidjson/writer.h
View file @
a1909a94
...
...
@@ -460,9 +460,14 @@ protected:
bool
WriteRawValue
(
const
Ch
*
json
,
size_t
length
)
{
PutReserve
(
*
os_
,
length
);
for
(
size_t
i
=
0
;
i
<
length
;
i
++
)
{
RAPIDJSON_ASSERT
(
json
[
i
]
!=
'\0'
);
PutUnsafe
(
*
os_
,
json
[
i
]);
GenericStringStream
<
SourceEncoding
>
is
(
json
);
while
(
RAPIDJSON_LIKELY
(
is
.
Tell
()
<
length
))
{
const
Ch
c
=
is
.
Peek
();
RAPIDJSON_ASSERT
(
c
!=
'\0'
);
if
(
RAPIDJSON_UNLIKELY
(
!
(
writeFlags
&
kWriteValidateEncodingFlag
?
Transcoder
<
SourceEncoding
,
TargetEncoding
>::
Validate
(
is
,
*
os_
)
:
Transcoder
<
SourceEncoding
,
TargetEncoding
>::
TranscodeUnsafe
(
is
,
*
os_
))))
return
false
;
}
return
true
;
}
...
...
test/unittest/writertest.cpp
View file @
a1909a94
...
...
@@ -538,6 +538,43 @@ TEST(Writer, RawValue) {
EXPECT_STREQ
(
"{
\"
a
\"
:1,
\"
raw
\"
:[
\"
Hello
\\
nWorld
\"
, 123.456]}"
,
buffer
.
GetString
());
}
TEST
(
Write
,
RawValue_Issue1152
)
{
{
GenericStringBuffer
<
UTF32
<>
>
sb
;
Writer
<
GenericStringBuffer
<
UTF32
<>
>
,
UTF8
<>
,
UTF32
<>
>
writer
(
sb
);
writer
.
RawValue
(
"null"
,
4
,
kNullType
);
EXPECT_TRUE
(
writer
.
IsComplete
());
const
unsigned
*
out
=
sb
.
GetString
();
EXPECT_EQ
(
static_cast
<
unsigned
>
(
'n'
),
out
[
0
]);
EXPECT_EQ
(
static_cast
<
unsigned
>
(
'u'
),
out
[
1
]);
EXPECT_EQ
(
static_cast
<
unsigned
>
(
'l'
),
out
[
2
]);
EXPECT_EQ
(
static_cast
<
unsigned
>
(
'l'
),
out
[
3
]);
EXPECT_EQ
(
static_cast
<
unsigned
>
(
0
),
out
[
4
]);
}
{
GenericStringBuffer
<
UTF8
<>
>
sb
;
Writer
<
GenericStringBuffer
<
UTF8
<>
>
,
UTF16
<>
,
UTF8
<>
>
writer
(
sb
);
writer
.
RawValue
(
L"null"
,
4
,
kNullType
);
EXPECT_TRUE
(
writer
.
IsComplete
());
EXPECT_STREQ
(
"null"
,
sb
.
GetString
());
}
{
// Fail in transcoding
GenericStringBuffer
<
UTF16
<>
>
buffer
;
Writer
<
GenericStringBuffer
<
UTF16
<>
>
,
UTF8
<>
,
UTF16
<>
>
writer
(
buffer
);
EXPECT_FALSE
(
writer
.
RawValue
(
"
\"\xfe\"
"
,
3
,
kStringType
));
}
{
// Fail in encoding validation
StringBuffer
buffer
;
Writer
<
StringBuffer
,
UTF8
<>
,
UTF8
<>
,
CrtAllocator
,
kWriteValidateEncodingFlag
>
writer
(
buffer
);
EXPECT_FALSE
(
writer
.
RawValue
(
"
\"\xfe\"
"
,
3
,
kStringType
));
}
}
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
static
Writer
<
StringBuffer
>
WriterGen
(
StringBuffer
&
target
)
{
Writer
<
StringBuffer
>
writer
(
target
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment