[PATCH] Bug #45599 - php_strip_tags() treats backslash character as an escape character inside HTML tags

From: Date: Thu, 16 Jul 2009 15:06:22 +0000
Subject: [PATCH] Bug #45599 - php_strip_tags() treats backslash character as an escape character inside HTML tags
Groups: php.internals 
Request: Send a blank email to internals+get-44986@lists.php.net to get a copy of this message
Patch files for php 5.x and 6 with a test. -- Herman Radtke hermanradtke@gmail.com | http://hermanradtke.com

Index: ext/standard/string.c =================================================================== --- ext/standard/string.c (revision 284189) +++ ext/standard/string.c (working copy) @@ -4367,7 +4367,7 @@ tp = ((tp-tbuf) >= PHP_TAG_BUF_SIZE ? tbuf: tp); *(tp++) = c; } - if (state && p != buf && *(p-1) != '\\' && (!in_q || *p == in_q)) { + if (state && p != buf && (state == 1 || *(p-1) != '\\') && (!in_q || *p == in_q)) { if (in_q) { in_q = 0; } else { Index: ext/standard/string.c =================================================================== --- ext/standard/string.c (revision 284189) +++ ext/standard/string.c (working copy) @@ -6519,7 +6519,7 @@ tp = ((tp-tbuf) >= UBYTES(PHP_TAG_BUF_SIZE) ? tbuf: tp); *(tp++) = ch; } - if (state && prev1 != 0x5C /*'\\'*/ && (!in_q || ch == in_q)) { + if (state && (state ==1 || prev1 != 0x5C /*'\\'*/) && (!in_q || ch == in_q)) { if (in_q) { in_q = 0; } else { @@ -6763,7 +6763,7 @@ tp = ((tp-tbuf) >= PHP_TAG_BUF_SIZE ? tbuf: tp); *(tp++) = c; } - if (state && p != buf && *(p-1) != '\\' && (!in_q || *p == in_q)) { + if (state && p != buf && (state ==1 || *(p-1) != '\\') && (!in_q || *p == in_q)) { if (in_q) { in_q = 0; } else { --TEST-- Bug #45599 (strip_tags() ignore backslash (\) character inside html tags) --FILE-- <?php echo strip_tags('Hello <a href="any\"> World') . "\n"; echo strip_tags('Hello <a href="any\\"> World') . "\n"; echo strip_tags('Hello <a href=\"any"> World'); ?> --EXPECT-- Hello World Hello World Hello World
« previous php.internals (#44986) next »