我当前使用以下代码在存储字符串之前对其进行清理:

ERB::Util::h(string)

我的问题出现在字符串已经被清理过的情况下,如下所示:
string = "Watching baseball `&` football"

经过消毒的字符串将如下所示:
sanitized_string = "Watching baseball `&` football"

我可以通过替换将<和>into>进行消毒吗?

最佳答案

先解围,然后再逃走:

require 'cgi'
string = "Watching baseball & football"

CGI.escapeHTML(CGI.unescapeHTML(string))

=> "Watching baseball & football"

关于ruby - Ruby sanitizer 代码…为什么要进行 sanitizer ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1603513/

10-12 14:16
查看更多