]> granicus.if.org Git - php/commitdiff
- Fixed bug #46578 (strip_tags() does not honor end-of-comment when it encounters...
authorFelipe Pena <felipe@php.net>
Fri, 21 Nov 2008 19:14:47 +0000 (19:14 +0000)
committerFelipe Pena <felipe@php.net>
Fri, 21 Nov 2008 19:14:47 +0000 (19:14 +0000)
ext/standard/string.c
ext/standard/tests/strings/bug46578.phpt [new file with mode: 0644]

index 30eb52e6018c445c93a30d944e0c8fc122e78c1e..693cff0cc67cdfc44760e43b111400fcc344c37f 100644 (file)
@@ -6538,7 +6538,10 @@ PHPAPI int php_u_strip_tags(UChar *rbuf, int len, int *stateptr, UChar *allow, i
 
                case 0x22: /* '"' */
                case 0x27: /* '\'' */
-                       if (state == 2 && prev1 != 0x5C) { /* '\\' */
+                       if (state == 4){
+                               /* Inside <!-- comment --> */
+                               break;
+                       } else if (state == 2 && prev1 != 0x5C) { /* '\\' */
                                if (last == ch) {
                                        last = 0x00;
                                } else if (last != 0x5C) {
@@ -6779,7 +6782,10 @@ PHPAPI size_t php_strip_tags_ex(char *rbuf, int len, int *stateptr, char *allow,
 
                        case '"':
                        case '\'':
-                               if (state == 2 && *(p-1) != '\\') {
+                               if (state == 4) {
+                                       /* Inside <!-- comment --> */
+                                       break;
+                               } else if (state == 2 && *(p-1) != '\\') {
                                        if (lc == c) {
                                                lc = '\0';
                                        } else if (lc != '\\') {
diff --git a/ext/standard/tests/strings/bug46578.phpt b/ext/standard/tests/strings/bug46578.phpt
new file mode 100644 (file)
index 0000000..ba9fbbe
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Bug #46578 (strip_tags() does not honor end-of-comment when it encounters a single quote)
+--FILE--
+<?php
+
+var_dump(strip_tags('<!-- testing I\'ve been to mars -->foobar'));
+
+var_dump(strip_tags('<a alt="foobar">foo<!-- foo! --></a>bar'));
+
+var_dump(strip_tags('<a alt="foobar"/>foo<?= foo! /* <!-- "cool" --> */ ?>bar'));
+
+var_dump(strip_tags('< ax'));
+
+var_dump(strip_tags('<! a>'));
+
+var_dump(strip_tags('<? ax'));
+
+?>
+--EXPECTF--
+%string|unicode%(6) "foobar"
+%string|unicode%(6) "foobar"
+%string|unicode%(6) "foobar"
+%string|unicode%(4) "< ax"
+%string|unicode%(0) ""
+%string|unicode%(0) ""