Skip to content

Commit

Permalink
Fix bug #40: string.sub broken for j=0 or j<i
Browse files Browse the repository at this point in the history
  • Loading branch information
fcr-- authored and paulcuth committed Jul 10, 2017
1 parent ddec86a commit d3f70d8
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vm/src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,7 @@
if (typeof s != 'string' && typeof s != 'number') throw new shine.Error("Bad argument #1 to 'sub' (string expected, got " + typeof s + ")");
s = '' + s;
i = i || 1;
j = j || s.length;
if (j === undefined) j = s.length;

if (i > 0) {
i = i - 1;
Expand All @@ -1933,6 +1933,7 @@
}

if (j < 0) j = s.length + j + 1;
if (i > j) return '';

return s.substring(i, j);
},
Expand Down

0 comments on commit d3f70d8

Please sign in to comment.