Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
8419bfbb
Unverified
Commit
8419bfbb
authored
Dec 12, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✅
improved test coverage
As we guarantee proper UTF-8 before, we do not need to cope with it later.
parent
569d275f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
15 deletions
+7
-15
json.hpp
src/json.hpp
+4
-12
unit-convenience.cpp
test/src/unit-convenience.cpp
+2
-2
unit-regression.cpp
test/src/unit-regression.cpp
+1
-1
No files found.
src/json.hpp
View file @
8419bfbb
...
...
@@ -6415,12 +6415,8 @@ class serializer
if
(
ensure_ascii
and
(
s
[
i
]
&
0x80
or
s
[
i
]
==
0x7F
))
{
const
auto
bytes
=
bytes_following
(
static_cast
<
uint8_t
>
(
s
[
i
]));
if
(
bytes
==
std
::
string
::
npos
)
{
// invalid characters are treated as is, so no
// additional space will be used
break
;
}
// invalid characters will be detected by throw_if_invalid_utf8
assert
(
bytes
!=
std
::
string
::
npos
);
if
(
bytes
==
3
)
{
...
...
@@ -6588,12 +6584,8 @@ class serializer
(
ensure_ascii
and
(
s
[
i
]
&
0x80
or
s
[
i
]
==
0x7F
)))
{
const
auto
bytes
=
bytes_following
(
static_cast
<
uint8_t
>
(
s
[
i
]));
if
(
bytes
==
std
::
string
::
npos
)
{
// copy invalid character as is
result
[
pos
++
]
=
s
[
i
];
break
;
}
// invalid characters will be detected by throw_if_invalid_utf8
assert
(
bytes
!=
std
::
string
::
npos
);
// check that the additional bytes are present
assert
(
i
+
bytes
<
s
.
size
());
...
...
test/src/unit-convenience.cpp
View file @
8419bfbb
...
...
@@ -101,10 +101,10 @@ TEST_CASE("convenience functions")
// invalid UTF-8 characters
CHECK_THROWS_AS
(
check_escaped
(
"ä
\xA9
ü"
),
json
::
type_error
);
CHECK_THROWS_WITH
(
check_escaped
(
"ä
\xA9
ü"
),
"[json.exception.type_error.316] invalid UTF-8 byte at index 2: 0xA9"
);
"[json.exception.type_error.316] invalid UTF-8 byte at index 2: 0xA9"
);
CHECK_THROWS_AS
(
check_escaped
(
"
\xC2
"
),
json
::
type_error
);
CHECK_THROWS_WITH
(
check_escaped
(
"
\xC2
"
),
"[json.exception.type_error.316] incomplete UTF-8 string; last byte: 0xC2"
);
"[json.exception.type_error.316] incomplete UTF-8 string; last byte: 0xC2"
);
}
}
test/src/unit-regression.cpp
View file @
8419bfbb
...
...
@@ -1309,7 +1309,7 @@ TEST_CASE("regression tests")
SECTION
(
"issue #838 - incorrect parse error with binary data in keys"
)
{
uint8_t
key1
[]
=
{
103
,
92
,
117
,
48
,
48
,
48
,
55
,
92
,
114
,
215
,
126
,
214
,
95
,
92
,
34
,
174
,
40
,
71
,
38
,
174
,
40
,
71
,
38
,
223
,
134
,
247
,
127
};
std
::
string
key1_str
(
key1
,
key1
+
sizeof
(
key1
)
/
sizeof
(
key1
[
0
]));
std
::
string
key1_str
(
key1
,
key1
+
sizeof
(
key1
)
/
sizeof
(
key1
[
0
]));
json
j
=
key1_str
;
CHECK_THROWS_AS
(
j
.
dump
(),
json
::
type_error
);
CHECK_THROWS_WITH
(
j
.
dump
(),
"[json.exception.type_error.316] invalid UTF-8 byte at index 10: 0x7E"
);
...
...
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