Skip to content

Commit

Permalink
Fixed getter for out-of-bounds integer properties of String objects
Browse files Browse the repository at this point in the history
  • Loading branch information
dop251 committed Oct 23, 2021
1 parent 7891d82 commit 1c1127b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
9 changes: 3 additions & 6 deletions string.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,9 @@ func (s *stringObject) getStr(name unistring.String, receiver Value) Value {
}

func (s *stringObject) getIdx(idx valueInt, receiver Value) Value {
i := int64(idx)
if i >= 0 {
if i < int64(s.length) {
return s._getIdx(int(i))
}
return nil
i := int(idx)
if i >= 0 && i < s.length {
return s._getIdx(i)
}
return s.baseObject.getStr(idx.string(), receiver)
}
Expand Down
14 changes: 14 additions & 0 deletions string_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package goja

import "testing"

func TestStringOOBProperties(t *testing.T) {
const SCRIPT = `
var string = new String("str");
string[4] = 1;
string[4];
`

testScript1(SCRIPT, valueInt(1), t)
}

0 comments on commit 1c1127b

Please sign in to comment.