Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

You must be a member of this account.

Add Fuse.String#split

#46

The native String#split method has several major bugs across all browsers (these are paraphrased from Steven Levithan's article; see http://blog.stevenlevithan.com/archives/cross-browser-split ):

  • IE & Safari 2-3 (and Konqueror) ignore RegExp capturing groups (example: 'a_b'.split(/(_)/) should return ["a", "_", "b"], instead, it returns ["a", "b"] in these buggy browsers).

  • Firefox ignores non-participating RegExp groups (see http://blog.stevenlevithan.com/archives/npcg-javascript ), and doesn't splice them into the resulting array as undefined

  • IE excludes empty values from the resulting array, but only for RegExes (strings work fine)

Steve goes on to implement a cross-browser solution to fix String#split, which I definitely think we could add to Fuse. However, his implementation uses RegExp decompilation (it breaks the separator RegExp down, then rebuilds it with an explicit g flag), which is extremely costly in all browsers.

Fuse.String#replace uses a RegExp's lastIndex property (instead of RegExp decompilation) to fix function replacement, and the code for fixing String#replace in Fuse and Steve's code for fixing String#split are not all that different. I was thinking of applying Steve's code for a Fuse.String#split implementation, but using a much faster lastIndex solution instead of decomp.

Reported by Kit Goncharov · July 17th, 2009 @ 09:23 PM

State: resolved
Milestone: none
Assigned to: John-David Dalton John-David Dalton

Activity

  1. Kit Goncharov
    Kit Goncharov
    • State changed from new to open

    July 17th, 2009 @ 09:49 PM

  2. Joe Gornick
    Joe Gornick
    • Milestone cleared.
    • State changed from open to new
    • Assigned user cleared.

    October 7th, 2009 @ 01:44 AM

  3. John-David Dalton
    John-David Dalton
    • State changed from new to resolved
    • Assigned user set to John-David Dalton

    this is now in core http://github.com/jdalton/fusejs/commit/577c92459a33102627141a3e5a90a2e45dff3d70, I updated the CHANGELOG later to include kit in the credits.

    April 15th, 2010 @ 02:31 AM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.