Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing regexp capture panic #477

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions builtin_regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,17 @@ func builtinRegExpTest(call FunctionCall) Value {
var start int
n := 1
re := call.runtime.global.RegExp
empty := stringValue("")
for i, v := range result[2:] {
if i%2 == 0 {
start = v
} else {
re.defineProperty(fmt.Sprintf("$%d", n), stringValue(target[start:v]), 0o100, false)
if v == -1 {
// No match for this part.
re.defineProperty(fmt.Sprintf("$%d", n), empty, 0o100, false)
} else {
re.defineProperty(fmt.Sprintf("$%d", n), stringValue(target[start:v]), 0o100, false)
}
n++
if n == 10 {
break
Expand All @@ -81,7 +87,6 @@ func builtinRegExpTest(call FunctionCall) Value {

if n <= 9 {
// Erase remaining.
empty := stringValue("")
for i := n; i <= 9; i++ {
re.defineProperty(fmt.Sprintf("$%d", i), empty, 0o100, false)
}
Expand Down
5 changes: 5 additions & 0 deletions issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,11 @@ func Test_issue317(t *testing.T) {
regexp: "(1+)-(2+)-(3+)-(4+)-(5+)-(6+)-(7+)-(8+)-(9+)-(X+)",
want: "",
},
"missing-match": {
input: "data:image/png;base64,",
regexp: "^data:(.*?)(;(.*?))??(;base64)?,",
want: "data:image/png;base64,,image/png,,,;base64,,,,,",
},
}

previous := ",,,,,,,,,"
Expand Down