2009-09-02 7 views
1

マークダウン形式のコメントをXMLドキュメントにバックアップしました。これは、もちろん、HTMLエスケープする必要があることを意味しました。 CGI.unescapeHTMLを使用しようとすると、すべてのブラウザでうまく表示されない、奇妙な文字がマークアップに追加されます。Ruby CGI.unescapeHTMLで奇妙な文字が生成される

具体的には、2つのスペースを "\ 302 \ 240"に置き換えますが、一貫していません。この動作を止めるにはどうすればよいですか?

例:

s = "I am seeing more and more <a href="http://github.com/aslakhellesoy/cucumber /tree/master">Cucumber</a> usage.  This is a good thing!  But I'm also seeing people who are not using regular expressions to their fullest.  Here are some quick regex tips to keep you features readable:

* `(?:a|an)` -- using a this construct you can group things wihout actually matching them.  I'm seeing a lot of steps that have unused params because someone needed a group but didn't know how to avoid capturing it&#x000A" 
CGI.unescapeHTML s 
# => "I am seeing more and more <a href=\"http://github.com/aslakhellesoy/cucumber/tree/master\">Cucumber</a> usage.\302\240 This is a good thing!\302\240 But I'm..." 
+0

どのバージョンをお使いですか?私は1.8.7でそれを見ていないよ。 –

+0

これは、Hamlが 文字をスペースとして追加したために発生していることがわかりました。 SOの書式設定が問題を取り除いたため、ここで動作します。それはこれを見つけるために数時間の作業でした。 –

答えて

0

ものは非改行スペースです。 Read up on wikipedia.

In computer-based text processing and digital typesetting, a 
non-breaking space, also known as a no-break space or 
non-breakable space (NBSP), is a variant of the space character 
that prevents an automatic line break (line wrap) at its position. 
In certain formats (such as HTML), it also prevents the 
“collapsing” of multiple consecutive whitespace characters into a 
single space. The non-breaking space is also known as a hard space 
or fixed space. In Unicode, it is encoded as U+00A0 no-break space 
(HTML: &#160; &nbsp;). 
関連する問題