Skip to content

Commit b61f7af

Browse files
committed
Fix lexing name starting with numner
Only [a-zA-z] were considered a separator to the next token, missing were [__git_main]. Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
1 parent 30b5c95 commit b61f7af

File tree

4 files changed

+26
-48
lines changed

4 files changed

+26
-48
lines changed

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ parameters:
10521052

10531053
-
10541054
message: "#^Parameter \\#1 \\$str of static method PhpMyAdmin\\\\SqlParser\\\\Context\\:\\:isSeparator\\(\\) expects string, mixed given\\.$#"
1055-
count: 4
1055+
count: 7
10561056
path: src/Lexer.php
10571057

10581058
-

psalm-baseline.xml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -695,21 +695,14 @@
695695
<code>$this-&gt;last</code>
696696
<code>$this-&gt;last</code>
697697
</LoopInvalidation>
698-
<MixedArrayAccess occurrences="43">
699-
<code>$this-&gt;str[$this-&gt;last + 1]</code>
700-
<code>$this-&gt;str[$this-&gt;last++]</code>
701-
<code>$this-&gt;str[$this-&gt;last]</code>
702-
<code>$this-&gt;str[$this-&gt;last]</code>
703-
<code>$this-&gt;str[$this-&gt;last]</code>
704-
<code>$this-&gt;str[$this-&gt;last]</code>
705-
<code>$this-&gt;str[$this-&gt;last]</code>
706-
<code>$this-&gt;str[$this-&gt;last]</code>
707-
<code>$this-&gt;str[$this-&gt;last]</code>
708-
<code>$this-&gt;str[$this-&gt;last]</code>
709-
<code>$this-&gt;str[$this-&gt;last]</code>
698+
<MixedArgument occurrences="3">
710699
<code>$this-&gt;str[$this-&gt;last]</code>
711700
<code>$this-&gt;str[$this-&gt;last]</code>
712701
<code>$this-&gt;str[$this-&gt;last]</code>
702+
</MixedArgument>
703+
<MixedArrayAccess occurrences="31">
704+
<code>$this-&gt;str[$this-&gt;last + 1]</code>
705+
<code>$this-&gt;str[$this-&gt;last++]</code>
713706
<code>$this-&gt;str[$this-&gt;last]</code>
714707
<code>$this-&gt;str[$this-&gt;last]</code>
715708
<code>$this-&gt;str[$this-&gt;last]</code>

src/Lexer.php

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ public function parseNumber()
842842
// or "E" causing wrongly interpreted scientific notation (".e[0 to 9]" is invalid). Such invalid notation could
843843
// break the lexer when table names under a given database context starts with ".e[0-9]".
844844
//
845-
// Valid final states are: 2, 3, 4 and 6. Any parsing that finished in a
845+
// Valid final states are: 2, 3, 4, 6, and 9. Any parsing that finished in a
846846
// state other than these is invalid.
847847
// Also, negative states are invalid states.
848848
$iBak = $this->last;
@@ -886,29 +886,25 @@ public function parseNumber()
886886
$state = 4;
887887
} elseif ($this->str[$this->last] === 'e' || $this->str[$this->last] === 'E') {
888888
$state = 5;
889-
} elseif (
890-
($this->str[$this->last] >= 'a' && $this->str[$this->last] <= 'z')
891-
|| ($this->str[$this->last] >= 'A' && $this->str[$this->last] <= 'Z')
892-
) {
893-
// A number can't be directly followed by a letter
894-
$state = -$state;
895-
break;
896889
} elseif ($this->str[$this->last] < '0' || $this->str[$this->last] > '9') {
890+
if (! Context::isSeparator($this->str[$this->last])) {
891+
// A number can't be directly followed by a letter _ or $
892+
$state = -$state;
893+
}
894+
897895
// Just digits and `.`, `e` and `E` are valid characters.
898896
break;
899897
}
900898
} elseif ($state === 4) {
901899
$flags |= Token::FLAG_NUMBER_FLOAT;
902900
if ($this->str[$this->last] === 'e' || $this->str[$this->last] === 'E') {
903901
$state = 5;
904-
} elseif (
905-
($this->str[$this->last] >= 'a' && $this->str[$this->last] <= 'z')
906-
|| ($this->str[$this->last] >= 'A' && $this->str[$this->last] <= 'Z')
907-
) {
908-
// A number can't be directly followed by a letter
909-
$state = -$state;
910-
break;
911902
} elseif ($this->str[$this->last] < '0' || $this->str[$this->last] > '9') {
903+
if (! Context::isSeparator($this->str[$this->last])) {
904+
// A number can't be directly followed by a letter _ or $
905+
$state = -$state;
906+
}
907+
912908
// Just digits, `e` and `E` are valid characters.
913909
break;
914910
}
@@ -919,14 +915,12 @@ public function parseNumber()
919915
|| ($this->str[$this->last] >= '0' && $this->str[$this->last] <= '9')
920916
) {
921917
$state = 6;
922-
} elseif (
923-
($this->str[$this->last] >= 'a' && $this->str[$this->last] <= 'z')
924-
|| ($this->str[$this->last] >= 'A' && $this->str[$this->last] <= 'Z')
925-
) {
926-
// A number can't be directly followed by a letter
927-
$state = -$state;
928-
break;
929918
} else {
919+
if (! Context::isSeparator($this->str[$this->last])) {
920+
// A number can't be directly followed by a letter _ or $
921+
$state = -$state;
922+
}
923+
930924
break;
931925
}
932926
} elseif ($state === 6) {

tests/data/lexer/lexNumberAtStartOfName.out

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,12 @@
4646
},
4747
{
4848
"@type": "PhpMyAdmin\\SqlParser\\Token",
49-
"token": "2",
50-
"value": 2,
51-
"keyword": null,
52-
"type": 6,
53-
"flags": 0,
54-
"position": 12
55-
},
56-
{
57-
"@type": "PhpMyAdmin\\SqlParser\\Token",
58-
"token": "_bar",
59-
"value": "_bar",
49+
"token": "2_bar",
50+
"value": "2_bar",
6051
"keyword": null,
6152
"type": 0,
6253
"flags": 0,
63-
"position": 13
54+
"position": 12
6455
},
6556
{
6657
"@type": "PhpMyAdmin\\SqlParser\\Token",
@@ -117,7 +108,7 @@
117108
"position": null
118109
}
119110
],
120-
"count": 12,
111+
"count": 11,
121112
"idx": 0
122113
},
123114
"delimiter": ";",

0 commit comments

Comments
 (0)