2
A
回答
0
一個簡單的白名單方法:
string input = "<span><b>99</b> < <i>100</i></span> <!-- 99 < 100 -->";
// escape & <and>
input = input.Replace("&", "&").Replace(">", ">").Replace("<", "<");
// unescape whitelisted tags
string output = input.Replace("<b>", "<b>").Replace("</b>", "</b>")
.Replace("<i>", "<i>").Replace("</i>", "</i>");
輸出:
<span><b>99</b> < <i>100</i></span> <!-- 99 < 100 -->
呈現的輸出:
<跨度> < </SPAN > < - 99 < 100 - >
0
假設標籤輸入爲喜歡這裏StackOverflow上一個字符串,您一定想先分割字符串成單個標籤:
string[] tags = "c# html lolcat ".Split(
new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
白色 - /黑名單可以使用HashSet<T>
存儲表示標籤:
HashSet<string> blacklist = new HashSet<string>(
StringComparer.CurrentCultureIgnoreCase) { "lolcat", "lolrus" };
然後你不得不檢查tags
之一是名單上:
bool invalid = tags.Any(blacklist.Contains);
0
你可以試試Html Agility Pack。我沒有試過它跳過標籤,但它肯定能找到標籤。
相關問題
- 1. DotNetOpenAuth白名單和黑名單如何工作?
- 2. 將AppEngine黑名單變爲白名單
- 3. phpunit白名單vs黑名單
- 4. Zend_Acl白名單VS黑名單?
- 5. 上傳的白名單或黑名單文件擴展名?
- 6. 白名單抑制
- 7. 使用PHP瞭解黑名單和白名單
- 8. python/django中的電子郵件白名單/黑名單
- 9. 內容腳本注入的多個白名單/黑名單?
- 10. 使用SecurityComponent :: requireSecure()將白名單列入黑名單
- 11. PHPUnit的白名單和黑名單似乎被忽略
- 12. 什麼是白名單和黑名單數據?
- 13. 黑名單或白名單過濾方法?
- 14. 白名單中的白名單主頁
- 15. 阿帕奇:實施黑名單/白名單訪問控制+ LDAP認證
- 16. Node Express中的緩存:您如何列出白名單/黑名單視圖?
- 17. 是否有可能[如何?]將shell_exec()命令列入黑名單和白名單?
- 18. YQL黑名單
- 19. 製作名單
- 20. PhoneGap白名單
- 21. Google API黑名單
- 22. chrome.webRequest API黑名單
- 23. 黑名單和preg_match
- 24. IP黑名單TcpServer
- 25. 來自例如白名單的白名單IFrame YouTube與AntiXSS
- 26. 如何製作黑白flash.media.Video?
- 27. 如何製作Chromecast API白名單網址頁面?
- 28. 如何製作測試的junit白名單運行
- 29. 您可以創建stylecop規則的白名單而不是黑名單嗎?
- 30. 在Java正則表達式中結合白名單和黑名單
你看這個? http://stackoverflow.com/questions/188870 – dtb 2009-09-18 01:03:23