Skip to content

Commit

Permalink
fix json sanitize bug with sci notation literals (#159)
Browse files Browse the repository at this point in the history
fixed bug with json sanitize, where the 'e' in json literals
using sci notation would be escaped, causing parse errors.
  • Loading branch information
cyrush committed Apr 18, 2017
1 parent 89d15ab commit 9980c5e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/libs/conduit/conduit_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,17 @@ json_sanitize(const std::string &json)

if( !in_id && check_word_char(json[i]))
{
in_id = true;
// accum id chars
cur_id += json[i];
emit = false;
// ids can't start with numbers ,
// check the prior char if it exists
if(i > 0 &&
!check_num_char(json[i-1]) &&
json[i-1] != '.')
{
in_id = true;
// accum id chars
cur_id += json[i];
emit = false;
}
}
else if(in_id) // finish the id
{
Expand Down
12 changes: 11 additions & 1 deletion src/tests/conduit/t_conduit_json_sanitize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

//-----------------------------------------------------------------------------
///
/// file: conduit_json_sanitize.cpp
/// file: t_conduit_json_sanitize.cpp
///
//-----------------------------------------------------------------------------

Expand Down Expand Up @@ -161,3 +161,13 @@ TEST(conduit_json_sanitize, simple_quoteless_schema)
delete [] data4;
}



//-----------------------------------------------------------------------------
TEST(conduit_json_sanitize, sci_notation)
{
std::string json_in = "{ \"data\": { \"value\": 1.2e-11 } }";

EXPECT_EQ(json_in,utils::json_sanitize(json_in));

}

0 comments on commit 9980c5e

Please sign in to comment.