Skip to content
Browse files

Support standard whitespace trimming.

  • Loading branch information...
1 parent aa8bf5d commit 4dd33d7d19c9cd555b051065efee76f06096da13 @ljharb ljharb committed Dec 30, 2013
Showing with 8 additions and 2 deletions.
  1. +2 −2 es5-shim.js
  2. +6 −0 tests/spec/s-global.js
View
4 es5-shim.js
@@ -1262,7 +1262,7 @@ if ("".substr && "0b".substr(-1) !== "b") {
}
// ES5 15.5.4.20
-// http://es5.github.com/#x15.5.4.20
+// whitespace from: http://es5.github.io/#x15.5.4.20
var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
"\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
"\u2029\uFEFF";
@@ -1283,7 +1283,7 @@ if (!String.prototype.trim || ws.trim()) {
}
// ES-5 15.1.2.2
-if (parseInt('08') !== 8) {
+if (parseInt(ws + '08') !== 8 || parseInt(ws + '0x16') !== 22) {
parseInt = (function (origParseInt) {
var hexRegex = /^0[xX]/;
return function parseIntES5(str, radix) {
View
6 tests/spec/s-global.js
@@ -28,6 +28,12 @@ describe('global methods', function () {
expect(parseInt(' 0x16')).toBe(parseInt('0x16', 16));
expect(parseInt(' 42')).toBe(parseInt('42', 10));
expect(parseInt(' 08')).toBe(parseInt('08', 10));
+
+ var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
+ "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
+ "\u2029\uFEFF";
+ expect(parseInt(ws + '08')).toBe(parseInt('08', 10));
+ expect(parseInt(ws + '0x16')).toBe(parseInt('0x16', 16));
});
it('defaults the radix properly when not a true number', function () {

0 comments on commit 4dd33d7

Please sign in to comment.
Something went wrong with that request. Please try again.