Convert non-breaking spaces to spaces in Ruby

Posted by CoolAJ86 on Stack Overflow See other posts from Stack Overflow or by CoolAJ86
Published on 2010-04-06T23:07:12Z Indexed on 2010/04/06 23:13 UTC
Read the original article Hit count: 671

Filed under:
|
|
|
|

I have cases where user-entered data from an html textarea or input is sometimes sent with \u00a0 (non-breaking spaces) instead of spaces when encoded as utf-8 json.

I believe that to be a bug in Firefox, as I know that the user isn't intentionally putting in non-breaking spaces instead of spaces.

There are also two bugs in Ruby, one of which can be used to combat the other.

For whatever reason

\s

doesn't match

\u00a0 

However

[^[:print:]]

(which definitely should not match) and

\xC2\xA0

both will match, but I consider those to be less-than-ideal ways to deal with the issue.

Are there other recommendations for getting around this issue?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about non-breaking-spaces