Skip to content

Commit 2791b08

Browse files
committed
Fixed bug where a regex that started with raised a syntax error
1 parent f6e6810 commit 2791b08

File tree

7 files changed

+91
-1
lines changed

7 files changed

+91
-1
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"extra": {
2929
"branch-alias": {
30-
"dev-master": "1.16.1-dev"
30+
"dev-master": "1.16.2-dev"
3131
}
3232
}
3333
}

doc/changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Changelog
22
==========
33

4+
#### 1.16.2
5+
* Fixed bug where a regex that started with `/=` raised a syntax error
6+
47
#### 1.16.1
58
* Fixed bug where, in some situations, scanner allowed invalid characters after a slash
69

lib/Peast/Syntax/Scanner.php

+5
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,11 @@ protected function isAfterSlash($position)
997997
elseif (in_array($char, $this->whitespaces) && !in_array($char, $this->lineTerminators)) {
998998
$idx--;
999999
}
1000+
//If "/=" is found, return true, this is the only operator that needs a special treatment
1001+
//since it can be also the start of a regex
1002+
elseif ($char === "=" && $this->charAt($idx - 1) === "/") {
1003+
return true;
1004+
}
10001005
//Different character, return
10011006
else {
10021007
break;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/=\n/;
2+
/**************************************************/
3+
/=\n/;
4+
/**************************************************/
5+
/=\n/;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[
2+
{
3+
"type": "RegularExpression",
4+
"value": "/=\\n/",
5+
"location": {
6+
"start": {
7+
"line": 1,
8+
"column": 0,
9+
"index": 0
10+
},
11+
"end": {
12+
"line": 1,
13+
"column": 5,
14+
"index": 5
15+
}
16+
}
17+
}
18+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/=\n/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"type": "Program",
3+
"location": {
4+
"start": {
5+
"line": 1,
6+
"column": 0,
7+
"index": 0
8+
},
9+
"end": {
10+
"line": 1,
11+
"column": 5,
12+
"index": 5
13+
}
14+
},
15+
"leadingComments": [],
16+
"trailingComments": [],
17+
"body": [
18+
{
19+
"type": "ExpressionStatement",
20+
"location": {
21+
"start": {
22+
"line": 1,
23+
"column": 0,
24+
"index": 0
25+
},
26+
"end": {
27+
"line": 1,
28+
"column": 5,
29+
"index": 5
30+
}
31+
},
32+
"leadingComments": [],
33+
"trailingComments": [],
34+
"expression": {
35+
"type": "RegExpLiteral",
36+
"location": {
37+
"start": {
38+
"line": 1,
39+
"column": 0,
40+
"index": 0
41+
},
42+
"end": {
43+
"line": 1,
44+
"column": 5,
45+
"index": 5
46+
}
47+
},
48+
"leadingComments": [],
49+
"trailingComments": [],
50+
"value": "/=\\n/",
51+
"raw": "/=\\n/",
52+
"flags": "",
53+
"pattern": "=\\n"
54+
}
55+
}
56+
],
57+
"sourceType": "script"
58+
}

0 commit comments

Comments
 (0)