From 6a33bb8656fe0546e8300021eaf3be04ec3c8b47 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sun, 24 Jan 2021 01:28:54 -0500 Subject: [PATCH] Lexer: Do not allow leading zero for number type --- src/Lexer.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Lexer.cpp b/src/Lexer.cpp index 461dace17..9da16cd2c 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -608,7 +608,8 @@ bool Lexer::isHexNumber (std::string& token, Lexer::Type& type) //////////////////////////////////////////////////////////////////////////////// // Lexer::Type::number -// \d+ +// 0 +// [1-9]\d* // [ . \d+ ] // [ e|E [ +|- ] \d+ [ . \d+ ] ] // not followed by non-operator. @@ -616,9 +617,16 @@ bool Lexer::isNumber (std::string& token, Lexer::Type& type) { std::size_t marker = _cursor; + bool leading_zero = (_text[marker] == '0'); + if (unicodeLatinDigit (_text[marker])) { ++marker; + + // Two (or more) digit number with a leading zero are not allowed + if (leading_zero && unicodeLatinDigit (_text[marker])) + return false; + while (unicodeLatinDigit (_text[marker])) utf8_next_char (_text, marker);