リンク
ちゃんと調べるときは
http://www.python.jp/doc/release/
Wiki内検索
最近更新したページ
最新コメント
文字コードの判定 by awesome things!
正規表現 by awesome things!
辞書 by stunning seo guys
文字列の16進変換 by check it out
文字コードの変換 by check this out
デバッガ by check this out
サブプロセス by watch for this
文字コードの判定 by watch for this
サニタイジング by check this out
タグ

サニタイジング

またはサニタイズ(sanitize)

半角で&quotって書くと、' に見えてしまうので全角にしてます。

>>> str = "<script language=\"javascript\">alert('Alert!')</script>"
>>>
>>> import cgi
>>>
>>> print cgi.escape(str)
&lt;script language="javascript"&gt;alert('Alert!')&lt;/script&gt;
>>>
>>> print cgi.escape(str, 1)
&lt;script language=&quot;javascript&quot;&gt;alert('Alert!')&lt;/script&gt;
>>>
>>> import xml.sax.saxutils
>>>
>>> print xml.sax.saxutils.quoteattr(str)
"&lt;script language=&quot;javascript&quot;&gt;alert('Alert!')&lt;/script&gt;"
>>>
>>> print xml.sax.saxutils.quoteattr(str, {"'": '&apos;'})
"&lt;script language=&quot;javascript&quot;&gt;alert(&apos;Alert!&apos;)&lt;/script&gt;"
>>>

全体がクォートされてしまうので取り除かないと。
2009年12月18日(金) 18:32:18 Modified by hebi_




スマートフォン版で見る