У меня есть сценарий Coldfusion, который некоторое время зависал в моей системе управления контентом.Он использует регулярные выражения для удаления любых дрянных тегов и символов из содержимого.
Мне нужно, чтобы этот скрипт не удалял любые теги <object>
и <iframe>
.попробую, но я думаю, что это выходит за рамки моих навыков регулярных выражений.
http://pastebin.com/rTtMyiQw
<cfparam name="Attributes.allowedclasses" default="">
<!--- turn allowed classes list to regular expression --->
<cfset Attributes.allowedclasses = Replace(Attributes.allowedclasses, ",", "|", "all")>
<cfset vBody="<body style='font-family:Verdana; font-size:12px;'>">
<cfset vStart="<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml' lang='en' xml:lang='en'><head><title>Title</title></head>#vBody#">
<cfset vEnd="</body></html>">
<cfloop list="#Attributes.varnames#" index="theVariable">
<cfset vIntVar=evaluate("caller.#theVariable#")>
<cf_bocctrimformvars varnames="vIntVar" allowhtml="yes" quotes="unescape" allowPound="yes">
<cfset vIntVarDebug=vIntVar>
<!--- strip copy and paste word etc code formatting --->
<cfset vIntVar=ReReplaceNoCase(vIntVar, "</?[a-z0-9-=""'!\$\?%&\*\+@~##;,\\]*:[a-z0-9 -=""'!\$\?%&\*\+@~##;,\\]*>", "", "all")>
<!--- stop certain classes being stripped out --->
<cfif ListLen(Attributes.allowedclasses) NEQ 0>
<cfset vIntVar=ReReplaceNoCase(vIntVar, '<span class="(#Attributes.allowedclasses#)">([\s\S]*?)</span>', '<excludespan classexclude="\1">\2</excludespan>', 'all')>
<!--- stop other classes being stripped out --->
<cfset vIntVar=ReReplaceNoCase(vIntVar, '<([a-z0-9]+) class="(#Attributes.allowedclasses#)"[^>]*>', '<\1 classexclude="\2">', 'all')>
</cfif>
<!--- strip out span and font tags --->
<cfset vIntVar=ReReplaceNoCase(vIntVar, "</?(span|font)[^>]*>", "", "all")>
<!--- strip out rest of styles/classes --->
<cfset vIntVar=ReReplaceNoCase(vIntVar, "<([a-z0-9]+) (style|class)=[^>]*>", "<\1>", "all")>
<!--- reset classes which shouldn't be stripped out --->
<cfif ListLen(Attributes.allowedclasses) NEQ 0>
<cfset vIntVar=ReReplaceNoCase(vIntVar, '<excludespan classexclude="([a-z0-9-]+)"[^>]*>', '<span class="\1">', 'all')>
<cfset vIntVar=ReplaceNoCase(vIntVar, '</excludespan>', '</span>', 'all')>
<cfset vIntVar=ReReplaceNoCase(vIntVar, '<([a-z0-9]+) classexclude="([a-z0-9-]+)"[^>]*>', '<\1 class="\2">', 'all')>
</cfif>
<cfset vIntVar=ReReplaceNoCase(vIntVar, "<\?xml[^>]*>", "", "all")>
<cfset vIntVar=ReReplaceNoCase(vIntVar, "<p>([[:space:]])*</p>", "", "all")>
<cfset vIntVar=ReReplaceNoCase(vIntVar, "</?U>", "", "all")>
<cfset vIntVar=ReReplaceNoCase(vIntVar, "</?DIV[^>]*>", "", "all")>
<cfset vIntVar=ReReplaceNoCase(vIntVar, "</?PRE>", "", "all")>
<cfset vIntVar=ReplaceNoCase(vIntVar, 'target=""', '', 'all')>
<!---
DG 19/9/2004: fix put in to swap round <p> and <a> tags if a single <p> is inside an <a>
(which html tidy doesn't like
--->
<cfset vIntVar=ReReplaceNoCase(vIntVar, "<a([[:print:]]*)>[[:space:]]*<p>([[:print:]]*)</p>([[:space:]]*)</a>", "<p><a\1>\2</a></p>", 'all')>
<cfset vIntVar=vStart & vIntVar & vEnd>
<cflock name="tidy" type="exclusive" timeout="10">
<cfscript>
TidyObj = CreateObject("COM", "TidyCOM.TidyObject");
TidyOptions = TidyObj.Options;
TidyOptions.Doctype = "omit";
TidyOptions.TidyMark = false;
TidyOptions.OutputXml = false;
TidyOptions.InputXml = false;
TidyOptions.OutputXhtml = true;
TidyOptions.ShowWarnings = false;
TidyOptions.DropEmptyParas = true;
TidyOptions.Quiet = true;
TidyOptions.Indent = 0;
TidyOptions.Wrap = 0;
TidyOptions.QuoteAmpersand = true;
vIntVar = TidyObj.TidyMemToMem(vIntVar);
TidyObj = "";
</cfscript>
</cflock>
<!--- strip any image tags inserted by drag and drop etc --->
<cfset vIntVar=ReReplaceNoCase(vIntVar, "<img [^>]*>", "", "all")>
</cfloop>