@@ -1366,6 +1366,7 @@ DNUM ({LNUM}?"."{LNUM})|({LNUM}"."{LNUM}?)
13661366EXPONENT_DNUM (({LNUM}|{DNUM})[eE][+-]?{LNUM})
13671367HNUM "0x"[0-9a-fA-F]+(_[0-9a-fA-F]+)*
13681368BNUM "0b"[01]+(_[01]+)*
1369+ ONUM "0o"[0-7]+(_[0-7]+)*
13691370LABEL [a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*
13701371WHITESPACE [ \n\r\t]+
13711372TABS_AND_SPACES [ \t]*
@@ -1950,6 +1951,51 @@ NEWLINE ("\r"|"\n"|"\r\n")
19501951 }
19511952}
19521953
1954+ <ST_IN_SCRIPTING>{ONUM} {
1955+ /* The +/- 2 skips "0o" */
1956+ size_t len = yyleng - 2 ;
1957+ char *end, *octal = yytext + 2 ;
1958+ zend_bool contains_underscores = (memchr (octal, ' _' , len) != NULL );
1959+
1960+ /* Skip any leading 0s */
1961+ while (len > 0 && (*octal == ' 0' || *octal == ' _' )) {
1962+ ++octal;
1963+ --len;
1964+ }
1965+
1966+ if (contains_underscores) {
1967+ octal = estrndup (octal, len);
1968+ strip_underscores (octal, &len);
1969+ }
1970+
1971+ errno = 0 ;
1972+
1973+ ZVAL_LONG (zendlval, ZEND_STRTOL (octal, &end, 8 ));
1974+
1975+ ZEND_ASSERT (end == octal + len);
1976+
1977+ if (!errno) {
1978+ if (contains_underscores) {
1979+ efree (octal);
1980+ }
1981+ RETURN_TOKEN_WITH_VAL (T_LNUMBER);
1982+ }
1983+
1984+ /* Overflow */
1985+ ZEND_ASSERT (errno == ERANGE);
1986+ /* Reset errno */
1987+ errno = 0 ;
1988+
1989+ /* zend_oct_strtod skips leading '0' */
1990+ ZVAL_DOUBLE (zendlval, zend_oct_strtod (octal, (const char **)&end));
1991+ ZEND_ASSERT (!errno);
1992+ ZEND_ASSERT (end == octal + len);
1993+ if (contains_underscores) {
1994+ efree (octal);
1995+ }
1996+ RETURN_TOKEN_WITH_VAL (T_DNUMBER);
1997+ }
1998+
19531999<ST_IN_SCRIPTING>{LNUM} {
19542000 size_t len = yyleng;
19552001 char *end, *lnum = yytext;
@@ -2071,7 +2117,7 @@ string:
20712117 RETURN_TOKEN_WITH_VAL (T_NUM_STRING);
20722118}
20732119
2074- <ST_VAR_OFFSET>{LNUM}|{HNUM}|{BNUM} { /* Offset must be treated as a string */
2120+ <ST_VAR_OFFSET>{LNUM}|{HNUM}|{BNUM}|{ONUM} { /* Offset must be treated as a string */
20752121 if (yyleng == 1 ) {
20762122 ZVAL_INTERNED_STR (zendlval, ZSTR_CHAR ((zend_uchar)*(yytext)));
20772123 } else {
0 commit comments