Skip to content

Commit

Permalink
trim semicolon and other white spaces before eval
Browse files Browse the repository at this point in the history
related to #566
  • Loading branch information
ysmood committed Mar 21, 2022
1 parent bde2c46 commit edc26bb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion page_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (e *EvalOptions) ByPromise() *EvalOptions {
}

func (e *EvalOptions) formatToJSFunc() string {
js := strings.TrimSpace(e.JS)
js := strings.Trim(e.JS, "\t\n\v\f\r ;")
return fmt.Sprintf(`function() { return (%s).apply(this, arguments) }`, js)
}

Expand Down
2 changes: 2 additions & 0 deletions page_eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func (t T) PageEval() {
(a, b) => a + b
`, 1, 2).Int())

t.Eq(page.MustEval(` ; () => 1; `).Int(), 1)

// reuse obj
obj := page.MustEvaluate(rod.Eval(`() => () => 'ok'`).ByObject())
t.Eq("ok", page.MustEval(`f => f()`, obj).Str())
Expand Down

0 comments on commit edc26bb

Please sign in to comment.