2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 02:49:00 +00:00

In JSONParser add lex_state ls_number_minus

This commit is contained in:
m-holger 2023-01-24 11:47:06 +00:00
parent b6b4d3b299
commit cba1c352e3
8 changed files with 30 additions and 6 deletions

View File

@ -647,6 +647,7 @@ namespace
enum lex_state_e {
ls_top,
ls_number,
ls_number_minus,
ls_alpha,
ls_string,
ls_backslash,
@ -861,7 +862,7 @@ JSONParser::getToken()
} else if ((*p >= 'a') && (*p <= 'z')) {
lex_state = ls_alpha;
} else if (*p == '-') {
lex_state = ls_number;
lex_state = ls_number_minus;
number_before_point = 0;
number_after_point = 0;
number_after_e = 0;
@ -891,6 +892,21 @@ JSONParser::getToken()
}
break;
case ls_number_minus:
if ((*p >= '1') && (*p <= '9')) {
++number_before_point;
lex_state = ls_number;
} else if (*p == '0') {
++number_before_point;
lex_state = ls_number;
} else {
QTC::TC("libtests", "JSON parse number minus no digits");
throw std::runtime_error(
"JSON: offset " + std::to_string(offset) +
": numeric literal: no digit after minus sign");
}
break;
case ls_number:
if ((*p >= '0') && (*p <= '9')) {
if (number_saw_e) {
@ -1020,6 +1036,7 @@ JSONParser::getToken()
break;
case ls_number:
case ls_number_minus:
case ls_alpha:
// okay
break;
@ -1093,8 +1110,9 @@ JSONParser::handleToken()
break;
case ls_number:
case ls_number_minus:
if (number_saw_point && (number_after_point == 0)) {
QTC::TC("libtests", "JSON parse decimal with no digits");
// QTC::TC("libtests", "JSON parse decimal with no digits");
throw std::runtime_error(
"JSON: offset " + std::to_string(offset) +
": decimal point with no digits");
@ -1108,7 +1126,7 @@ JSONParser::handleToken()
": number with leading zero");
}
if ((number_before_point == 0) && (number_after_point == 0)) {
QTC::TC("libtests", "JSON parse number no digits");
// QTC::TC("libtests", "JSON parse number no digits");
throw std::runtime_error(
"JSON: offset " + std::to_string(offset) +
": number with no digits");

View File

@ -58,7 +58,6 @@ QPDFArgParser bad option for help 0
QPDFArgParser bad topic for help 0
QPDFArgParser invalid choice handler to unknown 0
JSON parse junk after object 0
JSON parse decimal with no digits 0
JSON parse invalid keyword 0
JSON parse expected colon 0
JSON parse expected , or } 0
@ -76,11 +75,11 @@ JSON parse duplicate point 0
JSON parse duplicate e 0
JSON parse unexpected sign 0
JSON parse numeric bad character 0
JSON parse number minus no digits 0
JSON parse keyword bad character 0
JSON parse backslash bad character 0
JSON parse unterminated string 0
JSON parse leading zero 0
JSON parse number no digits 0
JSON parse premature end of u 0
JSON parse bad hex after u 0
JSONHandler unhandled value 0

View File

@ -121,6 +121,8 @@ my @bad = (
"high high surrogate", # 38
"dangling high surrogate", # 39
"duplicate dictionary key", # 40
"decimal point after minus",# 41
"e after minus", # 42
);
my $i = 0;

View File

@ -1 +1 @@
exception: bad-31.json: JSON: offset 2: number with no digits
exception: bad-31.json: JSON: offset 1: numeric literal: no digit after minus sign

View File

@ -0,0 +1,2 @@
-.123

View File

@ -0,0 +1 @@
exception: bad-41.json: JSON: offset 1: numeric literal: no digit after minus sign

View File

@ -0,0 +1 @@
-e123

View File

@ -0,0 +1 @@
exception: bad-42.json: JSON: offset 1: numeric literal: no digit after minus sign