Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/pugixml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8921,6 +8921,21 @@ PUGI_IMPL_NS_BEGIN
// parse integer part
while (PUGI_IMPL_IS_CHARTYPEX(*string, ctx_digit)) ++string;

// scientific notation no decimal part
if (*string == 'e' || *string == 'E')
{
++string;

// parse exponent sign
if (*string == '+' || *string == '-') ++string;

// there should be at least one digit in exponent
if (!PUGI_IMPL_IS_CHARTYPEX(*string, ctx_digit)) return false;

// parse exponent digits
while (PUGI_IMPL_IS_CHARTYPEX(*string, ctx_digit)) ++string;
}

// parse decimal part
if (*string == '.')
{
Expand All @@ -8929,6 +8944,21 @@ PUGI_IMPL_NS_BEGIN
while (PUGI_IMPL_IS_CHARTYPEX(*string, ctx_digit)) ++string;
}

// scientific notation with decimal part
if (*string == 'e' || *string == 'E')
{
++string;

// parse exponent sign
if (*string == '+' || *string == '-') ++string;

// there should be at least one digit in exponent
if (!PUGI_IMPL_IS_CHARTYPEX(*string, ctx_digit)) return false;

// parse exponent digits
while (PUGI_IMPL_IS_CHARTYPEX(*string, ctx_digit)) ++string;
}

// parse trailing whitespace
while (PUGI_IMPL_IS_CHARTYPE(*string, ct_space)) ++string;

Expand Down Expand Up @@ -9821,6 +9851,14 @@ PUGI_IMPL_NS_BEGIN

while (PUGI_IMPL_IS_CHARTYPEX(*cur, ctx_digit)) cur++;

// Scientific notation support
if (*cur == 'e' || *cur == 'E')
{
cur++;
if (*cur == '+' || *cur == '-') cur++;
while (PUGI_IMPL_IS_CHARTYPEX(*cur, ctx_digit)) cur++;
}

_cur_lexeme_contents.end = cur;

_cur_lexeme = lex_number;
Expand Down Expand Up @@ -9886,6 +9924,14 @@ PUGI_IMPL_NS_BEGIN
while (PUGI_IMPL_IS_CHARTYPEX(*cur, ctx_digit)) cur++;
}

// Scientific notation support
if (*cur == 'e' || *cur == 'E')
{
cur++;
if (*cur == '+' || *cur == '-') cur++;
while (PUGI_IMPL_IS_CHARTYPEX(*cur, ctx_digit)) cur++;
}

_cur_lexeme_contents.end = cur;

_cur_lexeme = lex_number;
Expand Down
9 changes: 8 additions & 1 deletion tests/test_xpath_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ TEST(xpath_number_parse)
CHECK_XPATH_NUMBER(c, STR(".123"), 0.123);
CHECK_XPATH_NUMBER(c, STR("123.4567890123456789012345"), 123.4567890123456789012345);
CHECK_XPATH_NUMBER(c, STR("123."), 123);
CHECK_XPATH_NUMBER(c, STR("number(-2.5E-2)"), -2.5E-2);
CHECK_XPATH_NUMBER(c, STR("-2.5E-2"), -2.5E-2);
CHECK_XPATH_NUMBER(c, STR("3.0e+5"), 3.0e+5);
CHECK_XPATH_NUMBER(c, STR("3.0e-5"), 3.0e-5);
CHECK_XPATH_NUMBER(c, STR("7.2e0"), 7.2e0);
CHECK_XPATH_NUMBER(c, STR("1e3"), 1e3);
CHECK_XPATH_NUMBER(c, STR("1.e3"), 1e3);
}

TEST(xpath_number_error)
Expand Down Expand Up @@ -376,7 +383,7 @@ TEST(xpath_parse_oom_propagation)
{
std::basic_string<char_t> literal(i, 'a');
std::basic_string<char_t> query = STR("processing-instruction('") + literal + STR("') | ") + query_base;

CHECK_ALLOC_FAIL(CHECK_XPATH_FAIL(query.c_str()));
}
}
Expand Down
Loading