我有一个正则表达式,如果给出错误的输入,它似乎就会停止工作。
我的代码:
function dbStr($string)
{
private static $tag = "(script|embed)";//As it turns out, embeds have the exact same syntax as scripts, so, we can use the same regexes against those :)
private static $tvnc = "(\\\\'|\\\\\"|[^<>\"'/])*?";//Tag Valid No Close
private static $quoteseq = "['\"](\\\\'|\\\\\"|[^\"'])*?['\"]";
private static $tvncq = "(".$tvnc.$quoteseq.$tvnc.")*?";//Tag Valid No Close Quotes
$string = preg_replace_callback
(
"#<".$tvnc.$tag."(".$tvncq."(src=".$quoteseq.")".$tvncq.")/>#imsSX",//Pattern
"dbStr_FilterSinglematch",//Callback
$string//Subject
);
return $string;
}
function dbStr_FilterSinglematch($m)
{
print_r($m);
return "";
}
现在,让我们说我称之为输入:
echo "\n" . dbStr
("
<script type='textjavascript' src='asdf'/>
<script type='textjavascript' src='asdf'>
asdfasfasdf
uyoiyoiuyoiuy
");
工作正常!它找到匹配项,并删除该匹配项。这是我从该电话发出的输出:
Array
(
[0] => <script type='textjavascript' src='asdf'/>
[1] =>
[2] => script
[3] => type='textjavascript' src='asdf'
[4] => type='textjavascript'
[5] => =
[6] => t
[7] =>
[8] => src='asdf'
[9] => f
)
<script type='textjavascript' src='asdf'>
asdfasfasdf
uyoiyoiuyoiuy
但是,如果我改为给它输入....
echo "test" . dbStr
(
'
<embed type="application/x-shockwave-flash" src="http://picasaweb.google.com/s/c/bin/slideshow.swf" width="288" height="192" flashvars="host=picasaweb.google.com&hl=en_US&feat=flashalbum&RGB=0x000000&feed=http%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2F109941697484668010012%2Falbumid%2F5561383933745906193%3Falt%3Drss%26kind%3Dphoto%26authkey%3DGv1sRgCN2H88H41qeT6AE%26hl%3Den_US" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>
'.
"
<script type='textjavascript' src='asdf'/>
<script fubar=\"d\\\\\'erp\" derp=\"dlerp\">
//<script type='text/javascript' src='asdf'/>
asdfasfasdf
</script>
<script>
uyoiyoiuyoiuy
</script>
");
无。什么都没有。 没有找到匹配项,但是我从正则表达式中获取的文本完全是空白的!
我的意思是,认真......到底是什么?这是我运行上面代码得到的输出:
test
是的,就是这样。
如果正则表达式找到任何匹配(例如,比如匹配整个文档),那么它不会从我的print_r()调用中输出一些内容吗?不,我认为它甚至不会召唤回调。正则表达式完全失败。
更糟糕的是,我设置了以下标头/ ini设置:
header('Content-type: text/plain');
error_reporting(E_ALL);
ini_set("display_errors", 1);
但我没有在我的日志或输出中看到任何错误!
所以,你有它,我的正则表达困境。有没有人知道为什么会失败?
编辑:
我缩小了问题的根源:
echo "test " . dbStr
('<embed tests="abc" tests="abc" flashvars="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"></embed>');
似乎当我有两个关于那个长的属性,然后是一个非常长的属性时,系统崩溃了。但是,这个输入不会崩溃...... :(有更多的A但没有前面的标签)
echo "test " . dbStr
('<embed
flashvars="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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