yui/yui3 — pull request #929 by ziggyism (2013-06-27 17:14:06+00:00)
Title: Y.Lang.trim doesn't always trim everything

*NOTE: This bug is naturally present in `trimLeft` and `trimRight` as well.*

This bug is mostly present in IE 6, 7, and 8. In these browsers, `String.prototype.trim` isn't present, and YUI falls back to a polyfill using the `\s` whitespace class to do the trimming. However, `\s` has flaws in these browsers and does not catch every possible piece of whitespace imaginable.

Here's a jsfiddle quickly describing what's going on: http://jsfiddle.net/K3FP7/4/

You'll notice YUI returns the correct length (zero) in the latest versions of Chrome, FF, Opera, and Safari because it feature detects `String.prototype.trim` and uses the native implementation, which correctly trims everything. Now load the fiddle in IE 6-8 and you'll notice the polyfill provided by YUI is inconsistent (because its polyfill relies on the flawed `\s` whitespace class).

There's also a bug in Firefox 3.5 where the native `String.prototype.trim` doesn't correctly trim all whitespace. It appears to be fixed in the latest version of FF, though.

I added:
* Unit tests to better detect these specific issues, as the current ones were too simple and did not include the weird and obscure pieces of whitespace.
* Utilization of the `Y.Lang._isNative` method to better feature detect trim, trimLeft, and trimRight (not sure why it wasn't being used before, as it will protect YUI from detecting another library's shim).
* Detection of whether `trim`, `trimLeft`, and `trimRight` actually do the right thing and trim everything (FF 3.5 issue, possibly others).
* Most importantly, a corrected whitespace class, to ensure all pieces of whitespace are caught and replaced in YUI's polyfill.

---------------------------

If anyone's interested, here is what ECMAScript 5.1 considers trimmable:

*Whitespace*
* `\u0009` - Tab
* `\u000B` - Vertical Tab
* `\u000C` - Form Feed
* `\u0020` - Space
* `\u00A0` - No-break space
* `\uFEFF` - Bye Order Mark
* Other category - Zs: All Unicode space separators are placed under a category called "Zs", which can be extracted from here (http://www.unicode.org/Public/UNIDATA/UnicodeData.txt, where the category of the code point is the 3rd column), or easily seen here: http://www.fileformat.info/info/unicode/category/Zs/list.htm

*Line Terminators*
* `\u000A` - Line Feed
* `\u000D` - Carriage Return
* `\u2028` - Line Separator
* `\u2029` - Paragraph Separator