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
127ce717
Commit
127ce717
authored
Apr 13, 2015
by
miloyip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a missing error handling for Writer, and add tests for invalid encoding.
parent
79433827
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
1 deletion
+32
-1
writer.h
include/rapidjson/writer.h
+2
-1
writertest.cpp
test/unittest/writertest.cpp
+30
-0
No files found.
include/rapidjson/writer.h
View file @
127ce717
...
@@ -303,7 +303,8 @@ protected:
...
@@ -303,7 +303,8 @@ protected:
}
}
}
}
else
else
Transcoder
<
SourceEncoding
,
TargetEncoding
>::
Transcode
(
is
,
*
os_
);
if
(
!
Transcoder
<
SourceEncoding
,
TargetEncoding
>::
Transcode
(
is
,
*
os_
))
return
false
;
}
}
os_
->
Put
(
'\"'
);
os_
->
Put
(
'\"'
);
return
true
;
return
true
;
...
...
test/unittest/writertest.cpp
View file @
127ce717
...
@@ -306,3 +306,32 @@ TEST(Writer, RootValueIsComplete) {
...
@@ -306,3 +306,32 @@ TEST(Writer, RootValueIsComplete) {
T
(
writer
.
String
(
""
));
T
(
writer
.
String
(
""
));
#undef T
#undef T
}
}
TEST
(
Writer
,
InvalidEncoding
)
{
// Fail in decoding invalid UTF-8 sequence http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
{
GenericStringBuffer
<
UTF16
<>
>
buffer
;
Writer
<
GenericStringBuffer
<
UTF16
<>
>
,
UTF8
<>
,
UTF16
<>
>
writer
(
buffer
);
writer
.
StartArray
();
EXPECT_FALSE
(
writer
.
String
(
"
\xfe
"
));
EXPECT_FALSE
(
writer
.
String
(
"
\xff
"
));
EXPECT_FALSE
(
writer
.
String
(
"
\xfe\xfe\xff\xff
"
));
writer
.
EndArray
();
}
// Fail in encoding
{
StringBuffer
buffer
;
Writer
<
StringBuffer
,
UTF32
<>
>
writer
(
buffer
);
static
const
UTF32
<>::
Ch
s
[]
=
{
0x110000
,
0
};
// Out of U+0000 to U+10FFFF
EXPECT_FALSE
(
writer
.
String
(
s
));
}
// Fail in unicode escaping in ASCII output
{
StringBuffer
buffer
;
Writer
<
StringBuffer
,
UTF32
<>
,
ASCII
<>
>
writer
(
buffer
);
static
const
UTF32
<>::
Ch
s
[]
=
{
0x110000
,
0
};
// Out of U+0000 to U+10FFFF
EXPECT_FALSE
(
writer
.
String
(
s
));
}
}
\ No newline at end of file
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