存储安全的HTML

时间:2014-07-23 11:04:27

标签: html mysql ruby escaping

我想下载一个网址列表,并将它们存储在数据库(Mysql)中。我该如何制作安全的htmls?我可以用什么代替

safe_html = make_safe_it(html) # HERE

在下面的代码中?

require 'mysql2'
require 'open-uri'

HOST = "..."
USER = "..."
PASS = "..."

@client = Mysql2::Client.new(:host=> HOST,:username=>USER,:password => PASS)
@client.query "USE db_test"
@client.query("SELECT id,url from pages").each{ |row|
   html = open(row["url"]).read
   safe_html = make_safe_it(html) # HERE
   @client.query("UPDATE pages SET html = #{safe_html} where id = #{row["id"]} ")
}

1 个答案:

答案 0 :(得分:0)

根据https://github.com/brianmario/mysql2使用escaped = client.escape("gi'thu\"bbe\0r's")

中的建议