Skip to content

Commit

Permalink
Parse numbers more strictly
Browse files Browse the repository at this point in the history
- Disallow not only zero but all digits after leading zero.
  • Loading branch information
ony committed Jun 28, 2016
1 parent e060a66 commit f518402
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/pjson_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,10 @@ static bool pj_magnitude_zero(pj_parser_ref parser, pj_token *token, const char
switch (*p)
{
case '-': case '+':
case '0':
case '0' ... '9':
/* leading zero must not be followed by another digit or any sign char */
pj_err_tok(parser, token);
return false;
case '1' ... '9':
return pj_magnitude_general(parser, token, ++p);
case '.':
return pj_fraction_start(parser, token, ++p);
case 'e': case 'E':
Expand Down
7 changes: 7 additions & 0 deletions test/number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ TEST(number, bad_numbers)

pj_poll(&parser, tokens.data(), tokens.size());
EXPECT_EQ( PJ_ERR, tokens[0].token_type ) << "00 shouldn't be a valid number";

pj_init(&parser, 0, 0);
sample = " 01 ";
pj_feed(&parser, sample);

pj_poll(&parser, tokens.data(), tokens.size());
EXPECT_EQ( PJ_ERR, tokens[0].token_type ) << "Leading zero must not be followed by another digit";
}

TEST(number, bad_fractons)
Expand Down

0 comments on commit f518402

Please sign in to comment.