[SOLVED] String in BBCode mit Funktion bearbeiten
Verfasst: 16.05.2004 16:27
Hi, ich möchte ein String in einem BBCode per htmlspecialchars vor XSS-Bugs schützen. Ich habe vorher die entsprechenden Zeichen einfach per regexp verboten, aber einige user wollen manche Zeichen trotzdem benutzen.
Ich habe mich an die Arbeit gemacht und erstmal, wie es beim quote-tag auch ist, "]" erlaubt.
Ich habe es allerdings jetzt schon mehrmals versucht und ich habe es nicht hingekriegt den String in meinem BBCode mit htmlspecialchars zu bearbeiten. Der BBCode geht so [showhide="bla"]fsfdasd[/showhide]. Das Bla soll mit htmlspecialchars gefiltert werden.
PS: Link zur aktuellen Version, die noch einige Sonderzeichen blockiert.
Ich habe mich an die Arbeit gemacht und erstmal, wie es beim quote-tag auch ist, "]" erlaubt.
Code: Alles auswählen
// Grab everything until the first "]"...
$possible_start = substr($text, $curr_pos, strpos($text, ']', $curr_pos + 1) - $curr_pos + 1);
//
// We're going to try and catch usernames with "[' characters.
//
if( preg_match('#\[quote=\\\"#si', $possible_start, $match) && !preg_match('#\[quote=\\\"(.*?)\\\"\]#si', $possible_start) )
{
// OK we are in a quote tag that probably contains a ] bracket.
// Grab a bit more of the string to hopefully get all of it..
if ($close_pos = strpos($text, '"]', $curr_pos + 9))
{
if (strpos(substr($text, $curr_pos + 9, $close_pos - ($curr_pos + 9)), '[quote') === false)
{
$possible_start = substr($text, $curr_pos, $close_pos - $curr_pos + 2);
}
}
}
//
// We're going to try and catch showhide-texts with "[' characters.
//
if( preg_match('#\[showhide=\\\"#si', $possible_start, $match) && !preg_match('#\[showhide=\\\"(.*?)\\\"\]#si', $possible_start) )
{
if ($close_pos = strpos($text, '"]', $curr_pos + 9))
{
if (strpos(substr($text, $curr_pos + 9, $close_pos - ($curr_pos + 9)), '[showhide') === false)
{
$possible_start = substr($text, $curr_pos, $close_pos - $curr_pos + 2);
}
}
}
PS: Link zur aktuellen Version, die noch einige Sonderzeichen blockiert.