Skip to content

Commit

Permalink
Fix string indexOf for empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Jan 23, 2023
1 parent 57d1429 commit 60dc6d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Jint.Tests/Runtime/StringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@ public void HasProperIteratorPrototypeChain()
Assert.True(engine.Evaluate("!iterator.hasOwnProperty(Symbol.iterator)").AsBoolean());
Assert.True(engine.Evaluate("iterator[Symbol.iterator]() === iterator").AsBoolean());
}

[Fact]
public void IndexOf()
{
var engine = new Engine();
Assert.Equal(0, engine.Evaluate("''.indexOf('', 0)"));
Assert.Equal(0, engine.Evaluate("''.indexOf('', 1)"));
}
}
4 changes: 2 additions & 2 deletions Jint/Native/String/StringPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -799,9 +799,9 @@ private JsValue IndexOf(JsValue thisObj, JsValue[] arguments)
pos = TypeConverter.ToInteger(arguments[1]);
}

if (pos >= s.Length)
if (pos > s.Length)
{
return JsNumber.IntegerNegativeOne;
pos = s.Length;
}

if (pos < 0)
Expand Down

0 comments on commit 60dc6d0

Please sign in to comment.