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
ff425196
Commit
ff425196
authored
Jan 14, 2015
by
Milo Yip
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #227 from miloyip/issue226nullstring
Correct Value(kStringType) and more assertions
parents
29fa1558
24563b28
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
2 deletions
+25
-2
document.h
include/rapidjson/document.h
+6
-1
documenttest.cpp
test/unittest/documenttest.cpp
+12
-0
valuetest.cpp
test/unittest/valuetest.cpp
+7
-1
No files found.
include/rapidjson/document.h
View file @
ff425196
...
...
@@ -457,11 +457,15 @@ public:
*/
explicit
GenericValue
(
Type
type
)
RAPIDJSON_NOEXCEPT
:
data_
(),
flags_
()
{
static
const
unsigned
defaultFlags
[
7
]
=
{
kNullFlag
,
kFalseFlag
,
kTrueFlag
,
kObjectFlag
,
kArrayFlag
,
k
Cons
tStringFlag
,
kNullFlag
,
kFalseFlag
,
kTrueFlag
,
kObjectFlag
,
kArrayFlag
,
k
Shor
tStringFlag
,
kNumberAnyFlag
};
RAPIDJSON_ASSERT
(
type
<=
kNumberType
);
flags_
=
defaultFlags
[
type
];
// Use ShortString to store empty string.
if
(
type
==
kStringType
)
data_
.
ss
.
SetLength
(
0
);
}
//! Explicit copy constructor (with allocator)
...
...
@@ -1399,6 +1403,7 @@ public:
if
(
!
handler
.
StartObject
())
return
false
;
for
(
ConstMemberIterator
m
=
MemberBegin
();
m
!=
MemberEnd
();
++
m
)
{
RAPIDJSON_ASSERT
(
m
->
name
.
IsString
());
// User may change the type of name by MemberIterator.
if
(
!
handler
.
Key
(
m
->
name
.
GetString
(),
m
->
name
.
GetStringLength
(),
(
m
->
name
.
flags_
&
kCopyFlag
)
!=
0
))
return
false
;
if
(
!
m
->
value
.
Accept
(
handler
))
...
...
test/unittest/documenttest.cpp
View file @
ff425196
...
...
@@ -212,6 +212,18 @@ TEST(Document, AcceptWriter) {
EXPECT_EQ
(
"{
\"
hello
\"
:
\"
world
\"
,
\"
t
\"
:true,
\"
f
\"
:false,
\"
n
\"
:null,
\"
i
\"
:123,
\"
pi
\"
:3.1416,
\"
a
\"
:[1,2,3,4]}"
,
os
.
str
());
}
// Issue 226: Value of string type should not point to NULL
TEST
(
Document
,
AssertAcceptInvalidNameType
)
{
Document
doc
;
doc
.
SetObject
();
doc
.
AddMember
(
"a"
,
0
,
doc
.
GetAllocator
());
doc
.
FindMember
(
"a"
)
->
name
.
SetNull
();
// Change name to non-string type.
OutputStringStream
os
;
Writer
<
OutputStringStream
>
writer
(
os
);
ASSERT_THROW
(
doc
.
Accept
(
writer
),
AssertException
);
}
// Issue 44: SetStringRaw doesn't work with wchar_t
TEST
(
Document
,
UTF16_Document
)
{
GenericDocument
<
UTF16
<>
>
json
;
...
...
test/unittest/valuetest.cpp
View file @
ff425196
...
...
@@ -600,7 +600,7 @@ TEST(Value, String) {
// Constructor with type
Value
y
(
kStringType
);
EXPECT_TRUE
(
y
.
IsString
());
EXPECT_
EQ
(
0
,
y
.
GetString
());
EXPECT_
STREQ
(
""
,
y
.
GetString
());
// Empty string should be "" instead of 0 (issue 226)
EXPECT_EQ
(
0u
,
y
.
GetStringLength
());
// SetConsttring()
...
...
@@ -677,6 +677,12 @@ TEST(Value, String) {
#endif // RAPIDJSON_HAS_STDSTRING
}
// Issue 226: Value of string type should not point to NULL
TEST
(
Value
,
SetStringNullException
)
{
Value
v
;
EXPECT_THROW
(
v
.
SetString
(
0
,
0
),
AssertException
);
}
TEST
(
Value
,
Array
)
{
Value
x
(
kArrayType
);
const
Value
&
y
=
x
;
...
...
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