Skip to content

Commit 915b02c

Browse files
committedSep 21, 2018
[MERGE #5714 @rhuanjl] Update String.padStart/padEnd to fix #5617
Merge pull request #5714 from rhuanjl:pad Early return for empty fillString even if padLength > max string length. Fixes #5617
2 parents 4b72289 + 138b62f commit 915b02c

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed
 

‎lib/Runtime/Library/JavascriptString.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -2090,11 +2090,6 @@ namespace Js
20902090
return mainString;
20912091
}
20922092

2093-
if (maxLength > JavascriptString::MaxCharLength)
2094-
{
2095-
JavascriptError::ThrowRangeError(scriptContext, JSERR_OutOfBoundString);
2096-
}
2097-
20982093
JavascriptString * fillerString = nullptr;
20992094
if (args.Info.Count > 2 && !JavascriptOperators::IsUndefinedObject(args[2], scriptContext))
21002095
{
@@ -2109,6 +2104,11 @@ namespace Js
21092104
}
21102105
}
21112106

2107+
if (maxLength > JavascriptString::MaxCharLength)
2108+
{
2109+
JavascriptError::ThrowRangeError(scriptContext, JSERR_OutOfBoundString);
2110+
}
2111+
21122112
if (fillerString == nullptr)
21132113
{
21142114
fillerString = NewWithBuffer(_u(" "), 1, scriptContext);

‎test/es7/stringpad.js

+5
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ var tests = [
6363
name: "String.prototype.padStart out of bound scenario",
6464
body: function () {
6565
assert.throws(() => { 'foo'.padStart(2147483647);}, RangeError, "index is out of bound", "String length is out of bound");
66+
assert.throws(() => { 'foo'.padEnd(2147483647);}, RangeError, "index is out of bound", "String length is out of bound");
67+
assert.doesNotThrow(() => { 'foo'.padStart(2147483647, '');}, "Out of bounds pad length does not throw when padding with empty string");
68+
assert.doesNotThrow(() => { 'foo'.padEnd(2147483647, '');}, "Out of bounds pad length does not throw when padding with empty string");
69+
assert.areEqual('foo'.padStart(2147483647, ''), 'foo', "String padded with empty string is returned even if length of padding > max string length");
70+
assert.areEqual('foo'.padEnd(2147483647, ''), 'foo', "String padded with empty string is returned even if length of padding > max string length");
6671
}
6772
}
6873
];

0 commit comments

Comments
 (0)
Please sign in to comment.