當從微軟的AntiXSSLibrary 4.0使用Sanitizer.GetSafeHtmlFragment,我注意到它改變了我的HTML片段:正則表達式來解決GetSafeHtmlFragment X_前綴
<pre class="brush: csharp">
</pre>
到:
<pre class="x_brush: x_csharp">
</pre>
可悲的是他們的API不允許我們禁用這種行爲。因此,我希望使用正則表達式(C#)來修復和替換類「x_anything」到「任何」的字符串,這些字符串出現在class =「」屬性中。
任何人都可以用RegEx幫助我做到這一點嗎?
感謝
UPDATE - 這個工作對我來說:
private string FixGetSafeHtmlFragment(string html)
{
string input = html;
Match match = Regex.Match(input, "class=\"(x_).+\"", RegexOptions.IgnoreCase);
if (match.Success)
{
string key = match.Groups[1].Value;
return input.Replace(key, "");
}
return html;
}
感謝,公民康涅狄格州。 – Anon2321