Skip to content

Commit

Permalink
Fixed bug where a regex that started with raised a syntax error
Browse files Browse the repository at this point in the history
  • Loading branch information
mck89 committed Mar 5, 2024
1 parent f6e6810 commit 2791b08
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.16.1-dev"
"dev-master": "1.16.2-dev"
}
}
}
3 changes: 3 additions & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Changelog
==========

#### 1.16.2
* Fixed bug where a regex that started with `/=` raised a syntax error

#### 1.16.1
* Fixed bug where, in some situations, scanner allowed invalid characters after a slash

Expand Down
5 changes: 5 additions & 0 deletions lib/Peast/Syntax/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,11 @@ protected function isAfterSlash($position)
elseif (in_array($char, $this->whitespaces) && !in_array($char, $this->lineTerminators)) {
$idx--;
}
//If "/=" is found, return true, this is the only operator that needs a special treatment
//since it can be also the start of a regex
elseif ($char === "=" && $this->charAt($idx - 1) === "/") {
return true;
}
//Different character, return
else {
break;
Expand Down
5 changes: 5 additions & 0 deletions test/Peast/Syntax/ES2015/files/Literal/Regexp10.Render.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/=\n/;
/**************************************************/
/=\n/;
/**************************************************/
/=\n/;
18 changes: 18 additions & 0 deletions test/Peast/Syntax/ES2015/files/Literal/Regexp10.Tokens.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"type": "RegularExpression",
"value": "/=\\n/",
"location": {
"start": {
"line": 1,
"column": 0,
"index": 0
},
"end": {
"line": 1,
"column": 5,
"index": 5
}
}
}
]
1 change: 1 addition & 0 deletions test/Peast/Syntax/ES2015/files/Literal/Regexp10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/=\n/
58 changes: 58 additions & 0 deletions test/Peast/Syntax/ES2015/files/Literal/Regexp10.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"type": "Program",
"location": {
"start": {
"line": 1,
"column": 0,
"index": 0
},
"end": {
"line": 1,
"column": 5,
"index": 5
}
},
"leadingComments": [],
"trailingComments": [],
"body": [
{
"type": "ExpressionStatement",
"location": {
"start": {
"line": 1,
"column": 0,
"index": 0
},
"end": {
"line": 1,
"column": 5,
"index": 5
}
},
"leadingComments": [],
"trailingComments": [],
"expression": {
"type": "RegExpLiteral",
"location": {
"start": {
"line": 1,
"column": 0,
"index": 0
},
"end": {
"line": 1,
"column": 5,
"index": 5
}
},
"leadingComments": [],
"trailingComments": [],
"value": "/=\\n/",
"raw": "/=\\n/",
"flags": "",
"pattern": "=\\n"
}
}
],
"sourceType": "script"
}

0 comments on commit 2791b08

Please sign in to comment.