fix lexer bugs: single quoted string with backslash and hnum, bnum out of range

This commit is contained in:
vadim 2017-12-06 12:35:05 +02:00
parent 829326f8f7
commit f9e21be04b
2 changed files with 15 additions and 4 deletions

View File

@ -11,7 +11,6 @@ package parser
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/z7zmey/php-parser/token" "github.com/z7zmey/php-parser/token"
) )
@ -798,7 +797,7 @@ yystate31:
switch { switch {
default: default:
goto yyabort goto yyabort
case c == '\'': case c >= '\x01' && c <= '\t' || c >= '\v' && c <= 'ÿ':
goto yystate29 goto yystate29
} }
@ -7597,6 +7596,9 @@ yyrule9: // {BNUM}
i := 2 i := 2
BNUMFOR: BNUMFOR:
for { for {
if i > len(tb)-1 {
break BNUMFOR
}
switch tb[i] { switch tb[i] {
case '0': case '0':
i++ i++
@ -7632,6 +7634,9 @@ yyrule11: // {HNUM}
i := 2 i := 2
HNUMFOR: HNUMFOR:
for { for {
if i > len(tb)-1 {
break HNUMFOR
}
switch tb[i] { switch tb[i] {
case '0': case '0':
i++ i++
@ -8406,7 +8411,7 @@ yyrule137: // .
l.begin(PHP) l.begin(PHP)
goto yystate0 goto yystate0
} }
yyrule138: // [\']([^\\\']*([\\][\'])*)*[\'] yyrule138: // [\']([^\\\']*([\\].)*)*[\']
{ {
lval.token = token.NewToken(l.handleNewLine(l.TokenBytes(nil))) lval.token = token.NewToken(l.handleNewLine(l.TokenBytes(nil)))
return T_CONSTANT_ENCAPSED_STRING return T_CONSTANT_ENCAPSED_STRING

View File

@ -93,6 +93,9 @@ NEW_LINE (\r|\n|\r\n)
tb := l.TokenBytes(nil) tb := l.TokenBytes(nil)
i:=2 i:=2
BNUMFOR:for { BNUMFOR:for {
if i > len(tb)-1 {
break BNUMFOR;
}
switch tb[i] { switch tb[i] {
case '0': i++; case '0': i++;
default: break BNUMFOR; default: break BNUMFOR;
@ -113,6 +116,9 @@ NEW_LINE (\r|\n|\r\n)
tb := l.TokenBytes(nil) tb := l.TokenBytes(nil)
i:=2 i:=2
HNUMFOR:for { HNUMFOR:for {
if i > len(tb)-1 {
break HNUMFOR;
}
switch tb[i] { switch tb[i] {
case '0': i++; case '0': i++;
default: break HNUMFOR; default: break HNUMFOR;
@ -254,7 +260,7 @@ NEW_LINE (\r|\n|\r\n)
<PROPERTY>{VAR_NAME} l.begin(PHP);lval.token = token.NewToken(l.handleNewLine(l.TokenBytes(nil))); return T_STRING; <PROPERTY>{VAR_NAME} l.begin(PHP);lval.token = token.NewToken(l.handleNewLine(l.TokenBytes(nil))); return T_STRING;
<PROPERTY>. l.ungetN(1);l.begin(PHP) <PROPERTY>. l.ungetN(1);l.begin(PHP)
<PHP>[\']([^\\\']*([\\][\'])*)*[\'] lval.token = token.NewToken(l.handleNewLine(l.TokenBytes(nil))); return T_CONSTANT_ENCAPSED_STRING; <PHP>[\']([^\\\']*([\\].)*)*[\'] lval.token = token.NewToken(l.handleNewLine(l.TokenBytes(nil))); return T_CONSTANT_ENCAPSED_STRING;
<PHP>` l.begin(BACKQUOTE); lval.token = token.NewToken(l.handleNewLine(l.TokenBytes(nil))); return rune2Class(rune(l.TokenBytes(nil)[0])) <PHP>` l.begin(BACKQUOTE); lval.token = token.NewToken(l.handleNewLine(l.TokenBytes(nil))); return rune2Class(rune(l.TokenBytes(nil)[0]))
<BACKQUOTE>` l.begin(PHP); lval.token = token.NewToken(l.handleNewLine(l.TokenBytes(nil))); return rune2Class(rune(l.TokenBytes(nil)[0])) <BACKQUOTE>` l.begin(PHP); lval.token = token.NewToken(l.handleNewLine(l.TokenBytes(nil))); return rune2Class(rune(l.TokenBytes(nil)[0]))