This project is archived and is in readonly mode.

#25 ✓invalid
Thomas Aylott

String.clean

Reported by Thomas Aylott | May 28th, 2008 @ 10:05 AM | in 2.0 (closed)

Originally posted on Trac by JanK

Original Trac Ticket

Description

String.clean replaces tabs and newlines with a space, but only if theres more than one consecutive whitespace, better would be to replace all whitespace by one space.

"foo\t\tbar".clean(); // "foo bar"
"foo\tbar".clean(); // "foo\tbar"

The regexp /\s+/g could replace the current regexp.

Trac Attachments

Trac Comments

Changed 4 months ago by kamicane


        
fixed in [1342] 

                  Changed 4 months ago by kamicane

          status
              changed from new to closed
        
          resolution
              set to fixed

fixed in [1342] 

          status
              changed from new to closed
        
          resolution
              set to fixed
        
      

Changed 4 months ago by daniel@…


        
It looks like IE has some serious problems with /s regex. IE ignores nbsp; and that is really strange, because another, a bit more descriptive notation, works well.  

Test page: 
http://daniel.steigerwald.cz/str... 

Please compare results in Firefox and Internet Explorer 7 

I suggest to use this: [ \f\n\r\t\v\u00A0\u2028\u2029]+/g  

                  Changed 4 months ago by daniel@…

          priority
              changed from trivial to critical
        
          status
              changed from closed to reopened
        
          resolution
            deleted

It looks like IE has some serious problems with /s regex. IE ignores nbsp; and that is really strange, because another, a bit more descriptive notation, works well.  

Test page: 
http://daniel.steigerwald.cz/str... 

Please compare results in Firefox and Internet Explorer 7 

I suggest to use this: [ \f\n\r\t\v\u00A0\u2028\u2029]+/g  

          priority
              changed from trivial to critical
        
          status
              changed from closed to reopened
        
          resolution
            deleted
        
      

Changed 4 months ago by anonymous


        
ECMAScript (PDF, see 1 5 .10.2.10) specifies \s as [\t\n\v\f\r], Firefox added [\u00A0\u2028\u2029] to the list if the docs are complete. 

Opera happens to match   with \s like Firefox. Safari behaves like the IE and doesnt match &nbsp with \s. 

I didnt test \u2028 and \u2029, but I think /[\s\u00A0\u2028\u2029]+/g should fix this for all browsers, as it adds firefox`s additions to \s. 

      

Changed 4 months ago by JanK


        
that was me, JanK 

      

Changed 4 months ago by tomocchino



                  Changed 4 months ago by tomocchino

          owner
              set to kamicane
        
          status
              changed from reopened to new

          owner
              set to kamicane
        
          status
              changed from reopened to new
        
      

Changed 4 months ago by anonymous


        
could be really useful links: 

http://blog.stevenlevithan.com/a... 
http://blog.stevenlevithan.com/a... 

sorry, i have no time to suggest code :( 

      

Changed 3 months ago by DanielSteigerwald


        
that was me, Daniel Steigerwald 

      

Changed 3 months ago by kamicane



                  Changed 3 months ago by kamicane

          priority
              changed from critical to trivial

          priority
              changed from critical to trivial
        
      

Changed 3 months ago by kamicane



                  Changed 3 months ago by kamicane

          milestone
              changed from Mootools version 1.2 to Mootools version 1.3

          milestone
              changed from Mootools version 1.2 to Mootools version 1.3
        
      

Changed 2 weeks ago by tomocchino



                  Changed 2 weeks ago by tomocchino

          priority
              changed from trivial to minor
        
          milestone
              set to Mootools version 1.3

          priority
              changed from trivial to minor
        
          milestone
              set to Mootools version 1.3
        
      

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Tags

Pages