Lors de l'écriture d'asp, nous devons prêter attention au traitement des chaînes spéciales pour éviter qu'elles ne soient exploitées par des pirates. Les amis qui utilisent asp doivent s'y référer.
Copiez le code comme suit :
'=======================================
'Convertir le contenu pour éviter les accidents
'=======================================
Fonction Content_Encode (ByVal t0)
SI IsNull(t0) Ou Len(t0)=0 Alors
Content_Encode=""
Autre
Content_Encode=Remplacer(t0,"<","<")
Content_Encode=Remplacer(Content_Encode,">",">")
Fin SI
Fonction de fin
'=======================================
'Déconvertir le contenu
'=======================================
Fonction Content_Decode (ByVal t0)
SI IsNull(t0) Ou Len(t0)=0 Alors
Content_Decode=""
Autre
Content_Decode=Remplacer(t0,"<","<")
Content_Decode=Remplacer(Content_Decode,">",">")
Fin SI
Fonction de fin
'=======================================
'Filtrer les caractères
'=======================================
Fonction FiltreTexte(ByVal t0,ByVal t1)
SI Len(t0)=0 Ou IsNull(t0) Ou IsArray(t0) Alors FilterText="":Fonction de sortie
t0 = Couper (t0)
Sélectionnez le cas t1
Cas "1"
t0=Remplacer(t0,Chr(32)," ")
t0=Remplacer(t0,Chr(13),"")
t0=Remplacer(t0,Chr(10)&Chr(10),"<br>")
t0=Remplacer(t0,Chr(10),"<br>")
Cas "2"
t0=Remplacer(t0,Chr(8),"")'retour
t0=Replace(t0,Chr(9),"")'tab (caractère de tabulation horizontale)
t0=Remplacer(t0,Chr(10),"")'Nouvelle ligne
t0=Replace(t0,Chr(11),"")'tab (caractère de tabulation vertical)
t0=Remplacer(t0,Chr(12),"")'Changement de page
t0=Replace(t0,Chr(13),"")' retour chariot chr(13)&chr(10) combinaison de retour chariot et de saut de ligne
t0=Remplacer(t0,Chr(22),"")
t0=Remplacer(t0,Chr(32),"")'ESPACE
t0=Remplacer(t0,Chr(33),"")'!
t0=Remplacer(t0,Chr(34),"")'"
t0=Remplacer(t0,Chr(35),"")'#
t0=Remplacer(t0,Chr(36),"")'$
t0=Remplacer(t0,Chr(37),"")'%
t0=Remplacer(t0,Chr(38),"")'&
t0=Remplacer(t0,Chr(39),"")''
t0=Remplacer(t0,Chr(40),"")'(
t0=Remplacer(t0,Chr(41),"")')
t0=Remplacer(t0,Chr(42),"")'*
t0=Remplacer(t0,Chr(43),"")'+
t0=Remplacer(t0,Chr(44),"")',
t0=Remplacer(t0,Chr(45),"")'-
t0=Remplacer(t0,Chr(46),"")'.
t0=Remplacer(t0,Chr(47),"")'/
t0=Remplacer(t0,Chr(58),"")' :
t0=Remplacer(t0,Chr(59),"")';
t0=Remplacer(t0,Chr(60),"")'<
t0=Remplacer(t0,Chr(61),"")'=
t0=Remplacer(t0,Chr(62),"")'>
t0=Remplacer(t0,Chr(63),"")' ?
t0=Remplacer(t0,Chr(64),"")'@
t0=Remplacer(t0,Chr(91),"")'/
t0=Remplacer(t0,Chr(92),"")'/
t0=Remplacer(t0,Chr(93),"")']
t0=Remplacer(t0,Chr(94),"")'^
t0=Remplacer(t0,Chr(95),"")'_
t0=Remplacer(t0,Chr(96),"")'`
t0=Remplacer(t0,Chr(123),"")'{
t0=Remplacer(t0,Chr(124),"")'|
t0=Remplacer(t0,Chr(125),"")'}
t0=Remplacer(t0,Chr(126),"")'~
Autre cas
t0=Remplacer(t0, "&", "&")
t0=Remplacer(t0, "'", "'")
t0=Remplacer(t0, """", """)
t0=Remplacer(t0, "<", "<")
t0=Remplacer(t0, ">", ">")
Fin de la sélection
SI Instr(Lcase(t0),"expression")>0 Alors
t0=Remplacer(t0,"expression","expression", 1, -1, 0)
Fin si
TexteFiltre=t0
Fonction de fin
'=======================================
'Filtrer les caractères communs et HTML
'=======================================
Fonction FiltreHtml(ByVal t0)
SI Len(t0)=0 Ou IsNull(t0) Ou IsArray(t0) Alors FilterHtml="":Fonction de sortie
SI Len(Sdcms_Badhtml)>0 Alors t0=ReplaceText(t0,"<(//|)("&Sdcms_Badhtml&")", "<$1$2")
SI Len(Sdcms_BadEvent)>0 Alors t0=ReplaceText(t0,"<(.[^>]*)("&Sdcms_BadEvent&")", "<$1$2")
t0=TexteFiltre(t0,0)
FiltreHtml=t0
Fonction de fin
Fonction GotTopic(ByVal t0,ByVal t1)
SI Len(t0)=0 Ou IsNull(t0) Alors
GotTopic=""
Fonction de sortie
Fin SI
Dim l, t, c, je
t0=Remplacer(Remplacer(Remplacer(t0," "," "),"",chr(34)),">",">"),"<","<")
l=Len(t0)
t=0
Pour I=1 À l
c=Abs(Asc(Mid(t0,i,1)))
SI c>255 Alors t=t+2 Sinon t=t+1
SI t>=t1 Alors
gotTopic=Gauche(t0,I)&"…"
Quitter pour
Autre
Sujet obtenu = t0
Fin SI
Suivant
GotTopic=Remplacer(Remplacer(Remplacer(Remplacer(GotTopic," "," "),chr(34),""),">",">"),"<","<")
Fonction de fin
Fonction UrlDecode(ByVal t0)
Dim t1,t2,t3,i,t4,t5,t6
t1=""
t2=Faux
t3=""
Pour I=1 À Len(t0)
t4=Milieu(t0,I,1)
SI t4="+" Alors
t1=t1&" "
SinonIF t4="%" Alors
t5=Milieu(t0,i+1,2)
t6=Cint("&H" & t5)
SI t2 Alors
t2=Faux
t1=t1&Chr(Cint("&H"&t3&t5))
Autre
SI Abs(t6)<=127 alors
t1=t1&Chr(t6)
Autre
t2=Vrai
t3=t5
Fin SI
Fin SI
je=je+2
Autre
t1=t1&t4
Fin SI
Suivant
UrlDécode=t1
Fonction de fin
Fonction CutStr(byVal t0,byVal t1)
Dim l, t, c, je
IF IsNull(t0) Then CutStr="":Fonction de sortie
l=Len(t0)
t1=Int(t1)
t=0
Pour I=1 À l
c=Asc(Milieu(t0,I,1))
SI c<0 Ou c>255 Alors t=t+2 Sinon t=t+1
SI t>=t1 Alors
CutStr=Gauche(t0,I)&"..."
Quitter pour
Autre
CoupeStr=t0
Fin SI
Suivant
Fonction de fin
Fonction CloseHtml(ByVal t0)
Dim t1,I,t2,t3,Regs,Correspondances,J,Correspondance
Définir Regs = Nouvelle RegExp
Regs.IgnoreCase=True
Regs.Global=Vrai
t1=Array("p","div","span","table","ul","font","b","u","i","h1","h2","h3 ","h4","h5","h6")
Pour I = 0 à UBound (t1)
t2=0
t3=0
Regs.Pattern="/<"&t1(I)&"( [^/</>]+|)/>"
Définir des correspondances = Regs.Execute (t0)
Pour chaque match dans les matchs
t2=t2+1
Suivant
Regs.Pattern="/</"&t1(I)&"/>"
Définir des correspondances = Regs.Execute (t0)
Pour chaque match dans les matchs
t3=t3+1
Suivant
Pour j=1 À t2-t3
t0=t0+"</"&t1(I)&">"
Suivant
Suivant
FermerHtml=t0
Fonction de fin