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
bfc003ca
Commit
bfc003ca
authored
Mar 17, 2020
by
chenguoping
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
catch exceptions for json_point : /xx/+99
parent
0feea616
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
80 deletions
+28
-80
include/nlohmann/detail/json_pointer.hpp
include/nlohmann/detail/json_pointer.hpp
+14
-40
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+14
-40
No files found.
include/nlohmann/detail/json_pointer.hpp
View file @
bfc003ca
...
...
@@ -329,6 +329,20 @@ class json_pointer
*/
static
int
array_index
(
const
std
::
string
&
s
)
{
// error condition (cf. RFC 6901, Sect. 4)
if
(
JSON_HEDLEY_UNLIKELY
(
s
.
size
()
>
1
and
s
[
0
]
==
'0'
))
{
JSON_THROW
(
detail
::
parse_error
::
create
(
106
,
0
,
"array index '"
+
s
+
"' must not begin with '0'"
));
}
// error condition (cf. RFC 6901, Sect. 4 & Sect. 7)
if
(
JSON_HEDLEY_UNLIKELY
(
s
.
size
()
>
1
and
not
(
s
[
0
]
>=
'1'
and
s
[
0
]
<=
'9'
)))
{
JSON_THROW
(
detail
::
parse_error
::
create
(
109
,
0
,
"array index '"
+
s
+
"' is not a number"
));
}
std
::
size_t
processed_chars
=
0
;
const
int
res
=
std
::
stoi
(
s
,
&
processed_chars
);
...
...
@@ -474,14 +488,6 @@ class json_pointer
case
detail
:
:
value_t
::
array
:
{
// error condition (cf. RFC 6901, Sect. 4)
if
(
JSON_HEDLEY_UNLIKELY
(
reference_token
.
size
()
>
1
and
reference_token
[
0
]
==
'0'
))
{
JSON_THROW
(
detail
::
parse_error
::
create
(
106
,
0
,
"array index '"
+
reference_token
+
"' must not begin with '0'"
));
}
if
(
reference_token
==
"-"
)
{
// explicitly treat "-" as index beyond the end
...
...
@@ -541,14 +547,6 @@ class json_pointer
") is out of range"
));
}
// error condition (cf. RFC 6901, Sect. 4)
if
(
JSON_HEDLEY_UNLIKELY
(
reference_token
.
size
()
>
1
and
reference_token
[
0
]
==
'0'
))
{
JSON_THROW
(
detail
::
parse_error
::
create
(
106
,
0
,
"array index '"
+
reference_token
+
"' must not begin with '0'"
));
}
// note: at performs range check
JSON_TRY
{
...
...
@@ -606,14 +604,6 @@ class json_pointer
") is out of range"
));
}
// error condition (cf. RFC 6901, Sect. 4)
if
(
JSON_HEDLEY_UNLIKELY
(
reference_token
.
size
()
>
1
and
reference_token
[
0
]
==
'0'
))
{
JSON_THROW
(
detail
::
parse_error
::
create
(
106
,
0
,
"array index '"
+
reference_token
+
"' must not begin with '0'"
));
}
// use unchecked array access
JSON_TRY
{
...
...
@@ -665,14 +655,6 @@ class json_pointer
") is out of range"
));
}
// error condition (cf. RFC 6901, Sect. 4)
if
(
JSON_HEDLEY_UNLIKELY
(
reference_token
.
size
()
>
1
and
reference_token
[
0
]
==
'0'
))
{
JSON_THROW
(
detail
::
parse_error
::
create
(
106
,
0
,
"array index '"
+
reference_token
+
"' must not begin with '0'"
));
}
// note: at performs range check
JSON_TRY
{
...
...
@@ -724,14 +706,6 @@ class json_pointer
return
false
;
}
// error condition (cf. RFC 6901, Sect. 4)
if
(
JSON_HEDLEY_UNLIKELY
(
reference_token
.
size
()
>
1
and
reference_token
[
0
]
==
'0'
))
{
JSON_THROW
(
detail
::
parse_error
::
create
(
106
,
0
,
"array index '"
+
reference_token
+
"' must not begin with '0'"
));
}
JSON_TRY
{
const
auto
idx
=
static_cast
<
size_type
>
(
array_index
(
reference_token
));
...
...
single_include/nlohmann/json.hpp
View file @
bfc003ca
...
...
@@ -10403,6 +10403,20 @@ class json_pointer
*/
static
int
array_index
(
const
std
::
string
&
s
)
{
// error condition (cf. RFC 6901, Sect. 4)
if
(
JSON_HEDLEY_UNLIKELY
(
s
.
size
()
>
1
and
s
[
0
]
==
'0'
))
{
JSON_THROW
(
detail
::
parse_error
::
create
(
106
,
0
,
"array index '"
+
s
+
"' must not begin with '0'"
));
}
// error condition (cf. RFC 6901, Sect. 4 & Sect. 7)
if
(
JSON_HEDLEY_UNLIKELY
(
s
.
size
()
>
1
and
not
(
s
[
0
]
>=
'1'
and
s
[
0
]
<=
'9'
)))
{
JSON_THROW
(
detail
::
parse_error
::
create
(
109
,
0
,
"array index '"
+
s
+
"' is not a number"
));
}
std
::
size_t
processed_chars
=
0
;
const
int
res
=
std
::
stoi
(
s
,
&
processed_chars
);
...
...
@@ -10548,14 +10562,6 @@ class json_pointer
case
detail
:
:
value_t
::
array
:
{
// error condition (cf. RFC 6901, Sect. 4)
if
(
JSON_HEDLEY_UNLIKELY
(
reference_token
.
size
()
>
1
and
reference_token
[
0
]
==
'0'
))
{
JSON_THROW
(
detail
::
parse_error
::
create
(
106
,
0
,
"array index '"
+
reference_token
+
"' must not begin with '0'"
));
}
if
(
reference_token
==
"-"
)
{
// explicitly treat "-" as index beyond the end
...
...
@@ -10615,14 +10621,6 @@ class json_pointer
") is out of range"
));
}
// error condition (cf. RFC 6901, Sect. 4)
if
(
JSON_HEDLEY_UNLIKELY
(
reference_token
.
size
()
>
1
and
reference_token
[
0
]
==
'0'
))
{
JSON_THROW
(
detail
::
parse_error
::
create
(
106
,
0
,
"array index '"
+
reference_token
+
"' must not begin with '0'"
));
}
// note: at performs range check
JSON_TRY
{
...
...
@@ -10680,14 +10678,6 @@ class json_pointer
") is out of range"
));
}
// error condition (cf. RFC 6901, Sect. 4)
if
(
JSON_HEDLEY_UNLIKELY
(
reference_token
.
size
()
>
1
and
reference_token
[
0
]
==
'0'
))
{
JSON_THROW
(
detail
::
parse_error
::
create
(
106
,
0
,
"array index '"
+
reference_token
+
"' must not begin with '0'"
));
}
// use unchecked array access
JSON_TRY
{
...
...
@@ -10739,14 +10729,6 @@ class json_pointer
") is out of range"
));
}
// error condition (cf. RFC 6901, Sect. 4)
if
(
JSON_HEDLEY_UNLIKELY
(
reference_token
.
size
()
>
1
and
reference_token
[
0
]
==
'0'
))
{
JSON_THROW
(
detail
::
parse_error
::
create
(
106
,
0
,
"array index '"
+
reference_token
+
"' must not begin with '0'"
));
}
// note: at performs range check
JSON_TRY
{
...
...
@@ -10798,14 +10780,6 @@ class json_pointer
return
false
;
}
// error condition (cf. RFC 6901, Sect. 4)
if
(
JSON_HEDLEY_UNLIKELY
(
reference_token
.
size
()
>
1
and
reference_token
[
0
]
==
'0'
))
{
JSON_THROW
(
detail
::
parse_error
::
create
(
106
,
0
,
"array index '"
+
reference_token
+
"' must not begin with '0'"
));
}
JSON_TRY
{
const
auto
idx
=
static_cast
<
size_type
>
(
array_index
(
reference_token
));
...
...
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