Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
f0050c9b
Unverified
Commit
f0050c9b
authored
May 02, 2020
by
Niels Lohmann
Committed by
GitHub
May 02, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2019 from dota17/contains_v2
fix #1982:json_pointer.contains() exception is incorrectly raised
parents
2251741b
8bfc6926
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
12 deletions
+51
-12
include/nlohmann/detail/json_pointer.hpp
include/nlohmann/detail/json_pointer.hpp
+21
-0
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+21
-0
test/src/unit-json_pointer.cpp
test/src/unit-json_pointer.cpp
+9
-12
No files found.
include/nlohmann/detail/json_pointer.hpp
View file @
f0050c9b
...
...
@@ -678,6 +678,27 @@ class json_pointer
// "-" always fails the range check
return
false
;
}
if
(
JSON_HEDLEY_UNLIKELY
(
reference_token
.
size
()
==
1
and
not
(
"0"
<=
reference_token
and
reference_token
<=
"9"
)))
{
// invalid char
return
false
;
}
if
(
JSON_HEDLEY_UNLIKELY
(
reference_token
.
size
()
>
1
))
{
if
(
JSON_HEDLEY_UNLIKELY
(
not
(
'1'
<=
reference_token
[
0
]
and
reference_token
[
0
]
<=
'9'
)))
{
// first char should be between '1' and '9'
return
false
;
}
for
(
std
::
size_t
i
=
1
;
i
<
reference_token
.
size
();
i
++
)
{
if
(
JSON_HEDLEY_UNLIKELY
(
not
(
'0'
<=
reference_token
[
i
]
and
reference_token
[
i
]
<=
'9'
)))
{
// other char should be between '0' and '9'
return
false
;
}
}
}
const
auto
idx
=
static_cast
<
size_type
>
(
array_index
(
reference_token
));
if
(
idx
>=
ptr
->
size
())
...
...
single_include/nlohmann/json.hpp
View file @
f0050c9b
...
...
@@ -11487,6 +11487,27 @@ class json_pointer
// "-" always fails the range check
return
false
;
}
if
(
JSON_HEDLEY_UNLIKELY
(
reference_token
.
size
()
==
1
and
not
(
"0"
<=
reference_token
and
reference_token
<=
"9"
)))
{
// invalid char
return
false
;
}
if
(
JSON_HEDLEY_UNLIKELY
(
reference_token
.
size
()
>
1
))
{
if
(
JSON_HEDLEY_UNLIKELY
(
not
(
'1'
<=
reference_token
[
0
]
and
reference_token
[
0
]
<=
'9'
)))
{
// first char should be between '1' and '9'
return
false
;
}
for
(
std
::
size_t
i
=
1
;
i
<
reference_token
.
size
();
i
++
)
{
if
(
JSON_HEDLEY_UNLIKELY
(
not
(
'0'
<=
reference_token
[
i
]
and
reference_token
[
i
]
<=
'9'
)))
{
// other char should be between '0' and '9'
return
false
;
}
}
}
const
auto
idx
=
static_cast
<
size_type
>
(
array_index
(
reference_token
));
if
(
idx
>=
ptr
->
size
())
...
...
test/src/unit-json_pointer.cpp
View file @
f0050c9b
...
...
@@ -310,12 +310,11 @@ TEST_CASE("JSON pointers")
CHECK_THROWS_AS
(
j_const
.
at
(
"/01"
_json_pointer
),
json
::
parse_error
&
);
CHECK_THROWS_WITH
(
j_const
.
at
(
"/01"
_json_pointer
),
"[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'"
);
CHECK_THROWS_AS
(
j
.
contains
(
"/01"
_json_pointer
),
json
::
parse_error
&
);
CHECK_THROWS_WITH
(
j
.
contains
(
"/01"
_json_pointer
),
"[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'"
);
CHECK_THROWS_AS
(
j_const
.
contains
(
"/01"
_json_pointer
),
json
::
parse_error
&
);
CHECK_THROWS_WITH
(
j_const
.
contains
(
"/01"
_json_pointer
),
"[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'"
);
CHECK
(
not
j
.
contains
(
"/01"
_json_pointer
));
CHECK
(
not
j
.
contains
(
"/01"
_json_pointer
));
CHECK
(
not
j_const
.
contains
(
"/01"
_json_pointer
));
CHECK
(
not
j_const
.
contains
(
"/01"
_json_pointer
));
// error with incorrect numbers
CHECK_THROWS_AS
(
j
[
"/one"
_json_pointer
]
=
1
,
json
::
parse_error
&
);
...
...
@@ -360,12 +359,10 @@ TEST_CASE("JSON pointers")
CHECK_THROWS_WITH
(
j_const
.
at
(
"/one"
_json_pointer
)
==
1
,
"[json.exception.parse_error.109] parse error: array index 'one' is not a number"
);
CHECK_THROWS_AS
(
j
.
contains
(
"/one"
_json_pointer
),
json
::
parse_error
&
);
CHECK_THROWS_WITH
(
j
.
contains
(
"/one"
_json_pointer
),
"[json.exception.parse_error.109] parse error: array index 'one' is not a number"
);
CHECK_THROWS_AS
(
j_const
.
contains
(
"/one"
_json_pointer
),
json
::
parse_error
&
);
CHECK_THROWS_WITH
(
j_const
.
contains
(
"/one"
_json_pointer
),
"[json.exception.parse_error.109] parse error: array index 'one' is not a number"
);
CHECK
(
not
j
.
contains
(
"/one"
_json_pointer
));
CHECK
(
not
j
.
contains
(
"/one"
_json_pointer
));
CHECK
(
not
j_const
.
contains
(
"/one"
_json_pointer
));
CHECK
(
not
j_const
.
contains
(
"/one"
_json_pointer
));
CHECK_THROWS_AS
(
json
({{
"/list/0"
,
1
},
{
"/list/1"
,
2
},
{
"/list/three"
,
3
}}).
unflatten
(),
json
::
parse_error
&
);
CHECK_THROWS_WITH
(
json
({{
"/list/0"
,
1
},
{
"/list/1"
,
2
},
{
"/list/three"
,
3
}}).
unflatten
(),
...
...
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