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
524974de
Commit
524974de
authored
May 03, 2015
by
miloyip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Validation of UTF-8 sequence for percent encoding, also improves coverage
parent
c35d47f8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
6 deletions
+25
-6
pointer.h
include/rapidjson/pointer.h
+2
-2
pointertest.cpp
test/unittest/pointertest.cpp
+23
-4
No files found.
include/rapidjson/pointer.h
View file @
524974de
...
...
@@ -429,7 +429,7 @@ private:
GenericInsituStringStream
<
EncodingType
>
os
(
name
);
Ch
*
begin
=
os
.
PutBegin
();
Transcoder
<
UTF8
<>
,
EncodingType
>
transcoder
;
if
(
!
transcoder
.
Transcod
e
(
is
,
os
)
||
!
is
.
IsValid
())
{
if
(
!
transcoder
.
Validat
e
(
is
,
os
)
||
!
is
.
IsValid
())
{
parseErrorCode_
=
kPointerParseErrorInvalidPercentEncoding
;
goto
error
;
}
...
...
@@ -538,7 +538,7 @@ private:
GenericStringStream
<
typename
ValueType
::
EncodingType
>
source
(
&
t
->
name
[
j
]);
PercentEncodeStream
<
OutputStream
>
target
(
os
);
Transcoder
<
EncodingType
,
UTF8
<>
>
transcoder
;
if
(
!
transcoder
.
Transcod
e
(
source
,
target
))
if
(
!
transcoder
.
Validat
e
(
source
,
target
))
return
false
;
j
+=
source
.
Tell
()
-
1
;
}
...
...
test/unittest/pointertest.cpp
View file @
524974de
...
...
@@ -340,7 +340,7 @@ TEST(Pointer, Parse_URIFragment) {
}
{
// kPointerParseErrorInvalidPercentEncoding
// kPointerParseErrorInvalidPercentEncoding
(invalid hex)
Pointer
p
(
"#/%g0"
);
EXPECT_FALSE
(
p
.
IsValid
());
EXPECT_EQ
(
kPointerParseErrorInvalidPercentEncoding
,
p
.
GetParseErrorCode
());
...
...
@@ -348,13 +348,21 @@ TEST(Pointer, Parse_URIFragment) {
}
{
// kPointerParseErrorInvalidPercentEncoding
// kPointerParseErrorInvalidPercentEncoding
(invalid hex)
Pointer
p
(
"#/%0g"
);
EXPECT_FALSE
(
p
.
IsValid
());
EXPECT_EQ
(
kPointerParseErrorInvalidPercentEncoding
,
p
.
GetParseErrorCode
());
EXPECT_EQ
(
2u
,
p
.
GetParseErrorOffset
());
}
{
// kPointerParseErrorInvalidPercentEncoding (incomplete UTF-8 sequence)
Pointer
p
(
"#/%C2"
);
EXPECT_FALSE
(
p
.
IsValid
());
EXPECT_EQ
(
kPointerParseErrorInvalidPercentEncoding
,
p
.
GetParseErrorCode
());
EXPECT_EQ
(
2u
,
p
.
GetParseErrorOffset
());
}
{
// kPointerParseErrorCharacterMustPercentEncode
Pointer
p
(
"#/ "
);
...
...
@@ -395,16 +403,23 @@ TEST(Pointer, Stringify) {
for
(
size_t
i
=
0
;
i
<
sizeof
(
sources
)
/
sizeof
(
sources
[
0
]);
i
++
)
{
Pointer
p
(
sources
[
i
]);
StringBuffer
s
;
p
.
Stringify
(
s
);
EXPECT_TRUE
(
p
.
Stringify
(
s
)
);
EXPECT_STREQ
(
sources
[
i
],
s
.
GetString
());
// Stringify to URI fragment
StringBuffer
s2
;
p
.
StringifyUriFragment
(
s2
);
EXPECT_TRUE
(
p
.
StringifyUriFragment
(
s2
)
);
Pointer
p2
(
s2
.
GetString
(),
s2
.
GetSize
());
EXPECT_TRUE
(
p2
.
IsValid
());
EXPECT_TRUE
(
p
==
p2
);
}
{
// Strigify to URI fragment with an invalid UTF-8 sequence
Pointer
p
(
"/
\xC2
"
);
StringBuffer
s
;
EXPECT_FALSE
(
p
.
StringifyUriFragment
(
s
));
}
}
// Construct a Pointer with static tokens, no dynamic allocation involved.
...
...
@@ -552,6 +567,10 @@ TEST(Pointer, Get) {
EXPECT_EQ
(
&
d
[
" "
],
Pointer
(
"/ "
).
Get
(
d
));
EXPECT_EQ
(
&
d
[
"m~n"
],
Pointer
(
"/m~0n"
).
Get
(
d
));
EXPECT_TRUE
(
Pointer
(
"/abc"
).
Get
(
d
)
==
0
);
EXPECT_TRUE
(
Pointer
(
"/foo/2"
).
Get
(
d
)
==
0
);
// Out of boundary
EXPECT_TRUE
(
Pointer
(
"/foo/a"
).
Get
(
d
)
==
0
);
// "/foo" is an array, cannot query by "a"
EXPECT_TRUE
(
Pointer
(
"/foo/0/0"
).
Get
(
d
)
==
0
);
// "/foo/0" is an string, cannot further query
EXPECT_TRUE
(
Pointer
(
"/foo/0/a"
).
Get
(
d
)
==
0
);
// "/foo/0" is an string, cannot further query
}
TEST
(
Pointer
,
GetWithDefault
)
{
...
...
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