将不间断空格转换为Ruby中的空格 [英] Convert non-breaking spaces to spaces in Ruby

查看:91
本文介绍了将不间断空格转换为Ruby中的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些情况下,来自html文本区域或输入的用户输入的数据有时会以\u00a0(不间断空格)发送,而不是编码为utf-8 json的空格.

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.

我相信这是Firefox中的错误,因为我知道用户并不是故意在不间断的空格中放置空格而不是空格.

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.

Ruby中还有两个错误,其中一个可以用来与另一个进行抗争.

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

由于任何原因\s\u00a0不匹配.

For whatever reason \s doesn't match \u00a0.

但是[^[:print:]],这两个绝对不匹配)和\xC2\xA0都将匹配,但是我认为这是处理问题的不理想方法.

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?

推荐答案

对于旧版本的ruby(1.8.x),修复程序是问题中所述的修复程序.

For the old versions of ruby (1.8.x), the fixes are the ones described in the question.

这在较新版本的ruby 1.9+中已得到修复.

This is fixed in the newer versions of ruby 1.9+.

这篇关于将不间断空格转换为Ruby中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆