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
e07686f0
Commit
e07686f0
authored
Mar 25, 2020
by
chenguoping
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update array_index() and add testcases
parent
dcd3a6c6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
4 deletions
+32
-4
include/nlohmann/detail/json_pointer.hpp
include/nlohmann/detail/json_pointer.hpp
+2
-2
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+2
-2
test/src/unit-json_pointer.cpp
test/src/unit-json_pointer.cpp
+28
-0
No files found.
include/nlohmann/detail/json_pointer.hpp
View file @
e07686f0
...
...
@@ -349,9 +349,9 @@ class json_pointer
{
res
=
std
::
stoi
(
s
,
&
processed_chars
);
}
JSON_CATCH
(
std
::
invalid_argument
&
)
JSON_CATCH
(
std
::
out_of_range
&
)
{
JSON_THROW
(
detail
::
parse_error
::
create
(
109
,
0
,
"array index '"
+
s
+
"' is not a number
"
));
JSON_THROW
(
detail
::
out_of_range
::
create
(
404
,
"unresolved reference token '"
+
s
+
"'
"
));
}
// check if the string was completely read
...
...
single_include/nlohmann/json.hpp
View file @
e07686f0
...
...
@@ -10423,9 +10423,9 @@ class json_pointer
{
res
=
std
::
stoi
(
s
,
&
processed_chars
);
}
JSON_CATCH
(
std
::
invalid_argument
&
)
JSON_CATCH
(
std
::
out_of_range
&
)
{
JSON_THROW
(
detail
::
parse_error
::
create
(
109
,
0
,
"array index '"
+
s
+
"' is not a number
"
));
JSON_THROW
(
detail
::
out_of_range
::
create
(
404
,
"unresolved reference token '"
+
s
+
"'
"
));
}
// check if the string was completely read
...
...
test/src/unit-json_pointer.cpp
View file @
e07686f0
...
...
@@ -332,6 +332,34 @@ 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
[
"/+1"
_json_pointer
]
=
1
,
json
::
parse_error
&
);
CHECK_THROWS_WITH
(
j
[
"/+1"
_json_pointer
]
=
1
,
"[json.exception.parse_error.109] parse error: array index '+1' is not a number"
);
CHECK_THROWS_AS
(
j_const
[
"/+1"
_json_pointer
]
==
1
,
json
::
parse_error
&
);
CHECK_THROWS_WITH
(
j_const
[
"/+1"
_json_pointer
]
==
1
,
"[json.exception.parse_error.109] parse error: array index '+1' is not a number"
);
CHECK_THROWS_AS
(
j
[
"/1+1"
_json_pointer
]
=
1
,
json
::
out_of_range
&
);
CHECK_THROWS_WITH
(
j
[
"/1+1"
_json_pointer
]
=
1
,
"[json.exception.out_of_range.404] unresolved reference token '1+1'"
);
CHECK_THROWS_AS
(
j_const
[
"/1+1"
_json_pointer
]
==
1
,
json
::
out_of_range
&
);
CHECK_THROWS_WITH
(
j_const
[
"/1+1"
_json_pointer
]
==
1
,
"[json.exception.out_of_range.404] unresolved reference token '1+1'"
);
CHECK_THROWS_AS
(
j
[
"/111111111111111111111111"
_json_pointer
]
=
1
,
json
::
out_of_range
&
);
CHECK_THROWS_WITH
(
j
[
"/111111111111111111111111"
_json_pointer
]
=
1
,
"[json.exception.out_of_range.404] unresolved reference token '111111111111111111111111'"
);
CHECK_THROWS_AS
(
j_const
[
"/111111111111111111111111"
_json_pointer
]
==
1
,
json
::
out_of_range
&
);
CHECK_THROWS_WITH
(
j_const
[
"/111111111111111111111111"
_json_pointer
]
==
1
,
"[json.exception.out_of_range.404] unresolved reference token '111111111111111111111111'"
);
CHECK_THROWS_AS
(
j
.
at
(
"/one"
_json_pointer
)
=
1
,
json
::
parse_error
&
);
CHECK_THROWS_WITH
(
j
.
at
(
"/one"
_json_pointer
)
=
1
,
"[json.exception.parse_error.109] parse error: array index 'one' is not a number"
);
CHECK_THROWS_AS
(
j_const
.
at
(
"/one"
_json_pointer
)
==
1
,
json
::
parse_error
&
);
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"
);
...
...
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