|
644 | 644 | overrideNative(String.prototype, 'includes', StringPrototypeShims.includes);
|
645 | 645 | }
|
646 | 646 |
|
647 |
| - var hasStringTrimBug = '\u0085'.trim().length !== 1; |
| 647 | + // whitespace from: http://es5.github.io/#x15.5.4.20 |
| 648 | + // implementation from https://github.com/es-shims/es5-shim/blob/v3.4.0/es5-shim.js#L1304-L1324 |
| 649 | + var ws = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004' + |
| 650 | + '\u2005\u2006\u2007\u2008\u2009\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF'; |
| 651 | + var hasStringTrimBug = ws.trim() || '\u0085\u002B'.trim().length !== 2; |
648 | 652 | if (hasStringTrimBug) {
|
649 | 653 | delete String.prototype.trim;
|
650 |
| - // whitespace from: http://es5.github.io/#x15.5.4.20 |
651 |
| - // implementation from https://github.com/es-shims/es5-shim/blob/v3.4.0/es5-shim.js#L1304-L1324 |
652 |
| - var ws = [ |
653 |
| - '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003', |
654 |
| - '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028', |
655 |
| - '\u2029\uFEFF' |
656 |
| - ].join(''); |
657 |
| - var trimRegexp = new RegExp('(^[' + ws + ']+)|([' + ws + ']+$)', 'g'); |
| 654 | + var wsRegexpChars = '[' + ws + '][' + ws + ']*'; |
| 655 | + var trimBeginRegexp = new RegExp('^' + wsRegexChars); |
| 656 | + var trimEndRegexp = new RegExp(wsRegexChars + '$'); |
658 | 657 | defineProperties(String.prototype, {
|
659 | 658 | trim: function trim() {
|
660 | 659 | if (typeof this === 'undefined' || this === null) {
|
661 | 660 | throw new TypeError("can't convert " + this + ' to object');
|
662 | 661 | }
|
663 |
| - return String(this).replace(trimRegexp, ''); |
| 662 | + return String(this).replace(trimBeginRegexp, '').replace(trimEndRegexp, ''); |
664 | 663 | }
|
665 | 664 | });
|
666 | 665 | }
|
|
0 commit comments