]> granicus.if.org Git - php/commitdiff
strip_tags() fixes:
authorArnaud Le Blanc <lbarnaud@php.net>
Fri, 24 Apr 2009 21:23:47 +0000 (21:23 +0000)
committerArnaud Le Blanc <lbarnaud@php.net>
Fri, 24 Apr 2009 21:23:47 +0000 (21:23 +0000)
- MFH5.3 (Fix bug when < is used within attribute.)
- Fix handling of case when searching for allowed tags in unicode variant
- tests for both unicode and binary variants

24 files changed:
ext/standard/string.c
ext/standard/tests/strings/bug21453_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/bug21744_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/bug22008_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/bug23650_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/bug40432_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/bug40637_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/bug40704_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/bug45485_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/bug46578_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/strip_tags_basic1_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/strip_tags_basic2_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/strip_tags_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/strip_tags_error_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/strip_tags_variation10_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/strip_tags_variation11_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/strip_tags_variation4.phpt
ext/standard/tests/strings/strip_tags_variation4_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/strip_tags_variation5_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/strip_tags_variation6_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/strip_tags_variation7.phpt
ext/standard/tests/strings/strip_tags_variation7_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/strip_tags_variation8_binary.phpt [new file with mode: 0644]
ext/standard/tests/strings/strip_tags_variation9_binary.phpt [new file with mode: 0644]

index ec500fc74dd0e3a4dd728a6dd851d81ffff40640..fe3cd237b0c958c03f81c15a0b143a690bf278ed 100644 (file)
@@ -6253,7 +6253,8 @@ int php_u_tag_find(UChar *tag, int len, UChar *set, int set_len)
 
        while (!done) {
                U16_NEXT(tag, idx, len, ch);
-               switch (u_tolower(ch)) {
+               ch = u_tolower(ch);
+               switch (ch) {
                case '<':
                        *(n++) = ch;
                        break;
@@ -6403,6 +6404,9 @@ PHPAPI int php_u_strip_tags(UChar *rbuf, int len, int *stateptr, UChar *allow, i
                        break;
 
                case 0x3C: /* '<' */
+                       if (in_q) {
+                               break;
+                       }
                        U16_GET(buf, 0, idx, len, next);
                        if (u_isWhitespace(next) == TRUE) {
                                goto reg_u_char;
diff --git a/ext/standard/tests/strings/bug21453_binary.phpt b/ext/standard/tests/strings/bug21453_binary.phpt
new file mode 100644 (file)
index 0000000..3d060c2
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Bug #21453 (handling of non-encoded <), binary variant
+--FILE--
+<?php
+$test = b"
+<table>
+       <tr><td>first cell before < first cell after</td></tr>
+       <tr><td>second cell before < second cell after</td></tr>
+</table>";
+
+       var_dump(strip_tags($test));
+?>
+--EXPECT--
+string(80) "
+
+       first cell before < first cell after
+       second cell before < second cell after
+"
diff --git a/ext/standard/tests/strings/bug21744_binary.phpt b/ext/standard/tests/strings/bug21744_binary.phpt
new file mode 100644 (file)
index 0000000..5ce5c5a
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Bug #21744 (strip_tags misses exclamation marks in alt text), binary variant
+--FILE--
+<?php
+$test = (binary) <<< HERE
+<a href="test?test\\!!!test">test</a>
+<!-- test -->
+HERE;
+
+print strip_tags($test, '');
+print strip_tags($test, '<a>');
+?>
+--EXPECT--
+test
+<a href="test?test\!!!test">test</a>
diff --git a/ext/standard/tests/strings/bug22008_binary.phpt b/ext/standard/tests/strings/bug22008_binary.phpt
new file mode 100644 (file)
index 0000000..4deefcc
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+Bug #22008 (strip_tags() eliminates too much), binary variant
+--FILE--
+<?php
+$html = (binary) <<< HERE
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<title>test</title>
+</head>
+<body>
+<b>PHP!</b>
+</body>
+</html>
+
+HERE;
+
+echo trim(strip_tags($html, '<b>'))."\n";
+?>
+--EXPECT--
+test
+
+
+<b>PHP!</b>
diff --git a/ext/standard/tests/strings/bug23650_binary.phpt b/ext/standard/tests/strings/bug23650_binary.phpt
new file mode 100644 (file)
index 0000000..dad98f1
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+Bug #23650 (strip_tags() removes hyphens), binary variant
+--FILE--
+<?php
+$str = (binary) <<< HERE
+1:<!-- abc -  -->
+2:<!doctype -- >
+3:
+4:<abc - def>
+5:abc - def
+6:</abc>
+
+HERE;
+
+echo strip_tags($str);
+echo strip_tags($str, b'<abc>');
+?>
+--EXPECT--
+1:
+2:
+3:
+4:
+5:abc - def
+6:
+1:
+2:
+3:
+4:<abc - def>
+5:abc - def
+6:</abc>
diff --git a/ext/standard/tests/strings/bug40432_binary.phpt b/ext/standard/tests/strings/bug40432_binary.phpt
new file mode 100644 (file)
index 0000000..e4076ea
--- /dev/null
@@ -0,0 +1,8 @@
+--TEST--
+Bug #40432 (strip_tags() fails with greater than in attribute), binary variant
+--FILE--
+<?php
+echo strip_tags(b'<span title="test > all">this</span>') . "\n";
+?>
+--EXPECT--
+this
diff --git a/ext/standard/tests/strings/bug40637_binary.phpt b/ext/standard/tests/strings/bug40637_binary.phpt
new file mode 100644 (file)
index 0000000..78ba084
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Bug #40637 (strip_tags() does not handle single quotes correctly), binary variant
+--FILE--
+<?php
+
+$html = b'<span title="Bug \' Trigger">Text</span>';
+var_dump(strip_tags($html));
+
+echo "Done\n";
+?>
+--EXPECT--
+unicode(4) "Text"
+Done
diff --git a/ext/standard/tests/strings/bug40704_binary.phpt b/ext/standard/tests/strings/bug40704_binary.phpt
new file mode 100644 (file)
index 0000000..6cb8d3a
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Bug #40704 (strip_tags() does not handle single quotes correctly), binary variant
+--FILE--
+<?php
+
+$html = b"<div>Bug ' Trigger</div> Missing Text";
+var_dump(strip_tags($html));
+
+echo "Done\n";
+?>
+--EXPECT--
+string(26) "Bug ' Trigger Missing Text"
+Done
diff --git a/ext/standard/tests/strings/bug45485_binary.phpt b/ext/standard/tests/strings/bug45485_binary.phpt
new file mode 100644 (file)
index 0000000..15e60c1
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+Bug #45485 (strip_tags and <?XML tag), binary variant
+--FILE--
+<?php
+
+$s = (binary) <<< EOD
+This text is shown <?XML:NAMESPACE PREFIX = ST1 /><b>This Text disappears</b>
+EOD;
+
+$s = strip_tags($s);
+echo htmlspecialchars($s),"\n";
+
+$s = (binary) <<< EOD
+This text is shown <?xml:NAMESPACE PREFIX = ST1 /><b>This Text disappears</b>
+EOD;
+
+$s = strip_tags($s);
+echo htmlspecialchars($s),"\n";
+
+?>
+--EXPECT--
+This text is shown This Text disappears
+This text is shown This Text disappears
diff --git a/ext/standard/tests/strings/bug46578_binary.phpt b/ext/standard/tests/strings/bug46578_binary.phpt
new file mode 100644 (file)
index 0000000..4cbbe4a
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Bug #46578 (strip_tags() does not honor end-of-comment when it encounters a single quote), binary variant
+--FILE--
+<?php
+
+var_dump(strip_tags(b'<!-- testing I\'ve been to mars -->foobar'));
+
+var_dump(strip_tags(b'<a alt="foobar">foo<!-- foo! --></a>bar'));
+
+var_dump(strip_tags(b'<a alt="foobar"/>foo<?= foo! /* <!-- "cool" --> */ ?>bar'));
+
+var_dump(strip_tags(b'< ax'));
+
+var_dump(strip_tags(b'<! a>'));
+
+var_dump(strip_tags(b'<? ax'));
+
+?>
+--EXPECTF--
+string(6) "foobar"
+string(6) "foobar"
+string(6) "foobar"
+string(4) "< ax"
+string(0) ""
+string(0) ""
diff --git a/ext/standard/tests/strings/strip_tags_basic1_binary.phpt b/ext/standard/tests/strings/strip_tags_basic1_binary.phpt
new file mode 100644 (file)
index 0000000..97c850e
--- /dev/null
@@ -0,0 +1,75 @@
+--TEST--
+Test strip_tags() function : basic functionality - with default arguments, binary variant
+--INI--
+short_open_tag = on
+--FILE--
+<?php
+/* Prototype  : string strip_tags(string $str [, string $allowable_tags])
+ * Description: Strips HTML and PHP tags from a string 
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing strip_tags() : basic functionality ***\n";
+
+// array of arguments 
+$string_array = array (
+  b"<html>hello</html>",
+  b'<html>hello</html>',
+  b"<?php echo hello ?>",
+  b'<?php echo hello ?>',
+  b"<? echo hello ?>",
+  b'<? echo hello ?>',
+  b"<% echo hello %>",
+  b'<% echo hello %>',
+  b"<script language=\"PHP\"> echo hello </script>",
+  b'<script language=\"PHP\"> echo hello </script>',
+  b"<html><b>hello</b><p>world</p></html>",
+  b'<html><b>hello</b><p>world</p></html>',
+  b"<html><!-- COMMENT --></html>",
+  b'<html><!-- COMMENT --></html>'
+);
+  
+               
+// Calling strip_tags() with default arguments
+// loop through the $string_array to test strip_tags on various inputs
+$iteration = 1;
+foreach($string_array as $string)
+{
+  echo "-- Iteration $iteration --\n";
+  var_dump( strip_tags($string) );
+  $iteration++;
+}
+
+echo "Done";
+?>
+--EXPECT--
+*** Testing strip_tags() : basic functionality ***
+-- Iteration 1 --
+string(5) "hello"
+-- Iteration 2 --
+string(5) "hello"
+-- Iteration 3 --
+string(0) ""
+-- Iteration 4 --
+string(0) ""
+-- Iteration 5 --
+string(0) ""
+-- Iteration 6 --
+string(0) ""
+-- Iteration 7 --
+string(0) ""
+-- Iteration 8 --
+string(0) ""
+-- Iteration 9 --
+string(12) " echo hello "
+-- Iteration 10 --
+string(12) " echo hello "
+-- Iteration 11 --
+string(10) "helloworld"
+-- Iteration 12 --
+string(10) "helloworld"
+-- Iteration 13 --
+string(0) ""
+-- Iteration 14 --
+string(0) ""
+Done
diff --git a/ext/standard/tests/strings/strip_tags_basic2_binary.phpt b/ext/standard/tests/strings/strip_tags_basic2_binary.phpt
new file mode 100644 (file)
index 0000000..27aa211
--- /dev/null
@@ -0,0 +1,61 @@
+--TEST--
+Test strip_tags() function : basic functionality - with all arguments, binary variant
+--INI--
+short_open_tag = on
+--FILE--
+<?php
+/* Prototype  : string strip_tags(string $str [, string $allowable_tags])
+ * Description: Strips HTML and PHP tags from a string
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing strip_tags() : basic functionality ***\n";
+
+// Calling strip_tags() with all possible arguments
+$string = b"<html><p>hello</p><b>world</b><a href=\"#fragment\">Other text</a></html><?php echo hello ?>";
+
+$allowed_tags_array=array(
+  b"<html>",
+  b'<html>',
+  b"<p>",
+  b'<p>',
+  b"<a>",
+  b'<a>',
+  b"<?php",
+  b'<?php',
+  b"<html><p><a><?php"
+);
+
+// loop through the $string with various $allowed_tags_array to test strip_tags
+// on various allowed tags
+$iteration = 1;
+foreach($allowed_tags_array as $tags)
+{
+  echo "-- Iteration $iteration --\n";
+  var_dump( strip_tags($string, $tags) );
+  $iteration++;
+}
+
+echo "Done";
+?>
+--EXPECT--
+*** Testing strip_tags() : basic functionality ***
+-- Iteration 1 --
+string(33) "<html>helloworldOther text</html>"
+-- Iteration 2 --
+string(33) "<html>helloworldOther text</html>"
+-- Iteration 3 --
+string(27) "<p>hello</p>worldOther text"
+-- Iteration 4 --
+string(27) "<p>hello</p>worldOther text"
+-- Iteration 5 --
+string(44) "helloworld<a href="#fragment">Other text</a>"
+-- Iteration 6 --
+string(44) "helloworld<a href="#fragment">Other text</a>"
+-- Iteration 7 --
+string(20) "helloworldOther text"
+-- Iteration 8 --
+string(20) "helloworldOther text"
+-- Iteration 9 --
+string(64) "<html><p>hello</p>world<a href="#fragment">Other text</a></html>"
+Done
diff --git a/ext/standard/tests/strings/strip_tags_binary.phpt b/ext/standard/tests/strings/strip_tags_binary.phpt
new file mode 100644 (file)
index 0000000..f307ec1
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+strip_tags() function, binary variant
+--FILE--
+<?php
+       echo strip_tags(b'NEAT <? cool < blah ?> STUFF');
+       echo "\n";
+       echo strip_tags(b'NEAT <? cool > blah ?> STUFF');
+       echo "\n";
+       echo strip_tags(b'NEAT <!-- cool < blah --> STUFF');
+       echo "\n";
+       echo strip_tags(b'NEAT <!-- cool > blah --> STUFF');
+       echo "\n";
+       echo strip_tags(b'NEAT <? echo \"\\\"\"?> STUFF');
+       echo "\n";
+       echo strip_tags(b'NEAT <? echo \'\\\'\'?> STUFF');
+       echo "\n";
+       echo strip_tags(b'TESTS ?!!?!?!!!?!!');
+       echo "\n";
+?>
+--EXPECT--
+NEAT  STUFF
+NEAT  STUFF
+NEAT  STUFF
+NEAT  STUFF
+NEAT  STUFF
+NEAT  STUFF
+TESTS ?!!?!?!!!?!!
diff --git a/ext/standard/tests/strings/strip_tags_error_binary.phpt b/ext/standard/tests/strings/strip_tags_error_binary.phpt
new file mode 100644 (file)
index 0000000..47dcba2
--- /dev/null
@@ -0,0 +1,40 @@
+--TEST--
+Test strip_tags() function : error conditions, binary variant
+--INI--
+short_open_tag = on
+--FILE--
+<?php
+/* Prototype  : string strip_tags(string $str [, string $allowable_tags])
+ * Description: Strips HTML and PHP tags from a string 
+ * Source code: ext/standard/string.c
+*/
+
+
+echo "*** Testing strip_tags() : error conditions ***\n";
+
+// Zero arguments
+echo "\n-- Testing strip_tags() function with Zero arguments --\n";
+var_dump( strip_tags() );
+
+//Test strip_tags with one more than the expected number of arguments
+echo "\n-- Testing strip_tags() function with more than expected no. of arguments --\n";
+$str = b"<html>hello</html>";
+$allowable_tags = b"<html>";
+$extra_arg = 10;
+var_dump( strip_tags($str, $allowable_tags, $extra_arg) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing strip_tags() : error conditions ***
+
+-- Testing strip_tags() function with Zero arguments --
+
+Warning: strip_tags() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+-- Testing strip_tags() function with more than expected no. of arguments --
+
+Warning: strip_tags() expects at most 2 parameters, 3 given in %s on line %d
+NULL
+Done
diff --git a/ext/standard/tests/strings/strip_tags_variation10_binary.phpt b/ext/standard/tests/strings/strip_tags_variation10_binary.phpt
new file mode 100644 (file)
index 0000000..7cc014e
--- /dev/null
@@ -0,0 +1,55 @@
+--TEST--
+Test strip_tags() function : usage variations - single quoted strings, binary variant
+--INI--
+short_open_tag = on
+--FILE--
+<?php
+/* Prototype  : string strip_tags(string $str [, string $allowable_tags])
+ * Description: Strips HTML and PHP tags from a string
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * testing functionality of strip_tags() by giving single quoted strings as values for $str argument
+*/
+
+echo "*** Testing strip_tags() : usage variations ***\n";
+
+
+$single_quote_string = array (
+  b'<html> \$ -> This represents the dollar sign</html><?php echo hello ?>',
+  b'<html>\t\r\v The quick brown fo\fx jumped over the lazy dog</p>',
+  b'<a>This is a hyper text tag</a>',
+  b'<? <html>hello world\\t</html>?>',
+  b'<p>This is a paragraph</p>',
+  b'<b>This is \ta text in bold letters\r\s\malong with slashes\n</b>'
+);
+
+$quotes = b"<html><a><p><b><?php";
+
+//loop through the various elements of strings array to test strip_tags() functionality
+$iterator = 1;
+foreach($single_quote_string as $string_value)
+{
+      echo "-- Iteration $iterator --\n";
+      var_dump( strip_tags($string_value, $quotes) );
+      $iterator++;
+}
+
+echo "Done";
+?>
+--EXPECT--
+*** Testing strip_tags() : usage variations ***
+-- Iteration 1 --
+string(51) "<html> \$ -> This represents the dollar sign</html>"
+-- Iteration 2 --
+string(63) "<html>\t\r\v The quick brown fo\fx jumped over the lazy dog</p>"
+-- Iteration 3 --
+string(31) "<a>This is a hyper text tag</a>"
+-- Iteration 4 --
+string(0) ""
+-- Iteration 5 --
+string(26) "<p>This is a paragraph</p>"
+-- Iteration 6 --
+string(65) "<b>This is \ta text in bold letters\r\s\malong with slashes\n</b>"
+Done
diff --git a/ext/standard/tests/strings/strip_tags_variation11_binary.phpt b/ext/standard/tests/strings/strip_tags_variation11_binary.phpt
new file mode 100644 (file)
index 0000000..f39657a
--- /dev/null
@@ -0,0 +1,41 @@
+--TEST--
+Test strip_tags() function : obscure values within attributes, binary variant
+--INI--
+short_open_tag = on
+--FILE--
+<?php
+
+echo "*** Testing strip_tags() : obscure functionality ***\n";
+
+// array of arguments
+$string_array = array (
+  b'hello <img title="<"> world',
+  b'hello <img title=">"> world',
+  b'hello <img title=">_<"> world',
+  b"hello <img title='>_<'> world"
+);
+
+
+// Calling strip_tags() with default arguments
+// loop through the $string_array to test strip_tags on various inputs
+$iteration = 1;
+foreach($string_array as $string)
+{
+  echo "-- Iteration $iteration --\n";
+  var_dump( strip_tags($string) );
+  $iteration++;
+}
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing strip_tags() : obscure functionality ***
+-- Iteration 1 --
+string(12) "hello  world"
+-- Iteration 2 --
+string(12) "hello  world"
+-- Iteration 3 --
+string(12) "hello  world"
+-- Iteration 4 --
+string(12) "hello  world"
+Done
index a77d231dc14f37933b3b001c1d4e0bf97139ea71..10066738ce364b9b84f99b7395f0a6fa4adff45d 100644 (file)
@@ -56,9 +56,9 @@ unicode(0) ""
 -- Iteration 4 --
 unicode(0) ""
 -- Iteration 5 --
-unicode(5) "hello"
+unicode(18) "<htmL>hello</htmL>"
 -- Iteration 6 --
-unicode(5) "hello"
+unicode(18) "<htmL>hello</htmL>"
 -- Iteration 7 --
 unicode(9) "HtMl text"
 -- Iteration 8 --
diff --git a/ext/standard/tests/strings/strip_tags_variation4_binary.phpt b/ext/standard/tests/strings/strip_tags_variation4_binary.phpt
new file mode 100644 (file)
index 0000000..6d290bc
--- /dev/null
@@ -0,0 +1,74 @@
+--TEST--
+Test strip_tags() function : usage variations - invalid values for 'str' and valid 'allowable_tags', binary variant
+--INI--
+short_open_tag = on
+--FILE--
+<?php
+/* Prototype  : string strip_tags(string $str [, string $allowable_tags])
+ * Description: Strips HTML and PHP tags from a string
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * testing functionality of strip_tags() by giving invalid values for $str and valid values for $allowable_tags argument
+*/
+
+echo "*** Testing strip_tags() : usage variations ***\n";
+
+// unexpected values for $string
+$strings = array (
+  b"<abc>hello</abc> \t\tworld... <ppp>strip_tags_test</ppp>",
+  b'<abc>hello</abc> \t\tworld... <ppp>strip_tags_test</ppp>',
+  b"<%?php hello\t world?%>",
+  b'<%?php hello\t world?%>',
+  b"<<htmL>>hello<</htmL>>",
+  b'<<htmL>>hello<</htmL>>',
+  b"<a.>HtMl text</.a>",
+  b'<a.>HtMl text</.a>',
+  b"<nnn>I am not a valid html text</nnn>",
+  b'<nnn>I am not a valid html text</nnn>',
+  b"<nnn>I am a quoted (\") string with special chars like \$,\!,\@,\%,\&</nnn>",
+  b'<nnn>I am a quoted (\") string with special chars like \$,\!,\@,\%,\&</nnn>',
+);
+
+//valid html and php tags
+$quotes = b"<p><a><?php<html>";
+
+//loop through the various elements of strings array to test strip_tags() functionality
+$iterator = 1;
+foreach($strings as $string_value)
+{
+      echo "-- Iteration $iterator --\n";
+      var_dump( strip_tags($string_value, $quotes) );
+      $iterator++;
+}
+
+echo "Done";
+?>
+--EXPECT--
+*** Testing strip_tags() : usage variations ***
+-- Iteration 1 --
+string(32) "hello              world... strip_tags_test"
+-- Iteration 2 --
+string(34) "hello \t\tworld... strip_tags_test"
+-- Iteration 3 --
+string(0) ""
+-- Iteration 4 --
+string(0) ""
+-- Iteration 5 --
+string(18) "<htmL>hello</htmL>"
+-- Iteration 6 --
+string(18) "<htmL>hello</htmL>"
+-- Iteration 7 --
+string(9) "HtMl text"
+-- Iteration 8 --
+string(9) "HtMl text"
+-- Iteration 9 --
+string(26) "I am not a valid html text"
+-- Iteration 10 --
+string(26) "I am not a valid html text"
+-- Iteration 11 --
+string(62) "I am a quoted (") string with special chars like $,\!,\@,\%,\&"
+-- Iteration 12 --
+string(64) "I am a quoted (\") string with special chars like \$,\!,\@,\%,\&"
+Done
diff --git a/ext/standard/tests/strings/strip_tags_variation5_binary.phpt b/ext/standard/tests/strings/strip_tags_variation5_binary.phpt
new file mode 100644 (file)
index 0000000..e7d3ffd
--- /dev/null
@@ -0,0 +1,105 @@
+--TEST--
+Test strip_tags() function : usage variations - heredoc strings, binary variant
+--INI--
+set short_open_tag = on
+--FILE--
+<?php
+/* Prototype  : string strip_tags(string $str [, string $allowable_tags])
+ * Description: Strips HTML and PHP tags from a string
+ * Source code: ext/standard/string.c
+*/
+
+
+/*
+ * testing functionality of strip_tags() by giving heredoc strings as values for $str argument
+*/
+
+echo "*** Testing strip_tags() : usage variations ***\n";
+
+// null here doc string
+$null_string = <<<EOT
+EOT;
+
+// heredoc string with blank line
+$blank_line = <<<EOT
+
+EOT;
+
+// here doc with multiline string
+$multiline_string = <<<EOT
+<html>hello world</html>
+<p>13 &lt; 25</p>
+<?php 1111 &amp; 0000 = 0000 ?>
+<b>This is a double quoted string</b>
+EOT;
+
+// here doc with diferent whitespaces
+$diff_whitespaces = <<<EOT
+<html>hello\r world\t
+1111\t\t != 2222\v\v</html>
+<? heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces ?>
+EOT;
+
+// here doc with numeric values
+$numeric_string = <<<EOT
+<html>11 < 12. 123 >22</html>
+<p>string</p> 1111\t <b>0000\t = 0000\n</b>
+EOT;
+
+// heredoc with quote chars & slash
+$quote_char_string = <<<EOT
+<html>This's a string with quotes:</html>
+"strings in double quote";
+'strings in single quote';
+<html>this\line is single quoted /with\slashes </html>
+EOT;
+
+$res_heredoc_strings = array(
+  //heredoc strings
+  $null_string,
+  $blank_line,
+  $multiline_string,
+  $diff_whitespaces,
+  $numeric_string,
+  $quote_char_string
+);
+
+// initialize the second argument
+$quotes = "<html><a><?php";
+
+// loop through $res_heredoc_strings element and check the working on strip_tags()
+$count = 1;
+for($index =0; $index < count($res_heredoc_strings); $index ++) {
+  echo "-- Iteration $count --\n";
+  var_dump( strip_tags((binary)$res_heredoc_strings[$index], (binary)$quotes) );
+  $count++;
+}
+
+echo "Done\n";
+?>
+--EXPECT--
+*** Testing strip_tags() : usage variations ***
+-- Iteration 1 --
+string(0) ""
+-- Iteration 2 --
+string(0) ""
+-- Iteration 3 --
+string(67) "<html>hello world</html>
+13 &lt; 25
+
+This is a double quoted string"
+-- Iteration 4 --
+string(44) "<html>hello
+ world 
+1111            != 2222\v\v</html>
+"
+-- Iteration 5 --
+string(56) "<html>11 < 12. 123 >22</html>
+string 1111     0000    = 0000
+"
+-- Iteration 6 --
+string(150) "<html>This's a string with quotes:</html>
+"strings in double quote";
+'strings in single quote';
+<html>this\line is single quoted /with\slashes </html>"
+Done
diff --git a/ext/standard/tests/strings/strip_tags_variation6_binary.phpt b/ext/standard/tests/strings/strip_tags_variation6_binary.phpt
new file mode 100644 (file)
index 0000000..1cdd1ab
--- /dev/null
@@ -0,0 +1,47 @@
+--TEST--
+Test strip_tags() function : usage variations - binary safe checking, binary variant
+--INI--
+short_open_tag = on
+--FILE--
+<?php
+/* Prototype  : string strip_tags(string $str [, string $allowable_tags])
+ * Description: Strips HTML and PHP tags from a string
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * testing whether strip_tags() is binary safe or not
+*/
+
+echo "*** Testing strip_tags() : usage variations ***\n";
+
+//various string inputs
+$strings = array (
+  "<html> I am html string </html>".chr(0)."<?php I am php string ?>",
+  "<html> I am html string\0 </html><?php I am php string ?>",
+  b"<a>I am html string</a>",
+  "<html>I am html string</html>".decbin(65)."<?php I am php string?>"
+);
+
+//loop through the strings array to check if strip_tags() is binary safe
+$iterator = 1;
+foreach($strings as $value)
+{
+      echo "-- Iteration $iterator --\n";
+      var_dump( strip_tags((binary)$value) );
+      $iterator++;
+}
+
+echo "Done";
+?>
+--EXPECT--
+*** Testing strip_tags() : usage variations ***
+-- Iteration 1 --
+string(18) " I am html string "
+-- Iteration 2 --
+string(18) " I am html string "
+-- Iteration 3 --
+string(16) "I am html string"
+-- Iteration 4 --
+string(23) "I am html string1000001"
+Done
index a0c2a2400fed9354fb91256a5dd062c454274a5f..c7f94491da22d95bd42a0739ec7d89bbceb73b7c 100644 (file)
@@ -54,9 +54,9 @@ unicode(0) ""
 -- Iteration 4 --
 unicode(0) ""
 -- Iteration 5 --
-unicode(5) "hello"
+unicode(18) "<htmL>hello</htmL>"
 -- Iteration 6 --
-unicode(5) "hello"
+unicode(18) "<htmL>hello</htmL>"
 -- Iteration 7 --
 unicode(9) "HtMl text"
 -- Iteration 8 --
diff --git a/ext/standard/tests/strings/strip_tags_variation7_binary.phpt b/ext/standard/tests/strings/strip_tags_variation7_binary.phpt
new file mode 100644 (file)
index 0000000..bb87f2d
--- /dev/null
@@ -0,0 +1,72 @@
+--TEST--
+Test strip_tags() function : usage variations - invalid values for 'str' and 'allowable_tags', binary variant
+--INI--
+short_open_tag = on
+--FILE--
+<?php
+/* Prototype  : string strip_tags(string $str [, string $allowable_tags])
+ * Description: Strips HTML and PHP tags from a string
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * testing functionality of strip_tags() by giving invalid values for $str and $allowable_tags argument
+*/
+
+echo "*** Testing strip_tags() : usage variations ***\n";
+
+$strings = array (
+  b"<abc>hello</abc> \t\tworld... <ppp>strip_tags_test</ppp>",
+  b'<abc>hello</abc> \t\tworld... <ppp>strip_tags_test</ppp>',
+  b"<%?php hello\t world?%>",
+  b'<%?php hello\t world?%>',
+  b"<<htmL>>hello<</htmL>>",
+  b'<<htmL>>hello<</htmL>>',
+  b"<a.>HtMl text</.a>",
+  b'<a.>HtMl text</.a>',
+  b"<nnn>I am not a valid html text</nnn>",
+  b'<nnn>I am not a valid html text</nnn>',
+  b"<nnn>I am a quoted (\") string with special chars like \$,\!,\@,\%,\&</nnn>",
+  b'<nnn>I am a quoted (\") string with special chars like \$,\!,\@,\%,\&</nnn>',
+);
+
+$quotes = b"<nnn><abc><%?<<html>>";
+
+//loop through the various elements of strings array to test strip_tags() functionality
+$iterator = 1;
+foreach($strings as $string_value)
+{
+      echo "-- Iteration $iterator --\n";
+      var_dump( strip_tags($string_value, $quotes) );
+      $iterator++;
+}
+
+echo "Done";
+?>
+--EXPECT--
+*** Testing strip_tags() : usage variations ***
+-- Iteration 1 --
+string(43) "<abc>hello</abc>           world... strip_tags_test"
+-- Iteration 2 --
+string(45) "<abc>hello</abc> \t\tworld... strip_tags_test"
+-- Iteration 3 --
+string(0) ""
+-- Iteration 4 --
+string(0) ""
+-- Iteration 5 --
+string(18) "<htmL>hello</htmL>"
+-- Iteration 6 --
+string(18) "<htmL>hello</htmL>"
+-- Iteration 7 --
+string(9) "HtMl text"
+-- Iteration 8 --
+string(9) "HtMl text"
+-- Iteration 9 --
+string(37) "<nnn>I am not a valid html text</nnn>"
+-- Iteration 10 --
+string(37) "<nnn>I am not a valid html text</nnn>"
+-- Iteration 11 --
+string(73) "<nnn>I am a quoted (") string with special chars like $,\!,\@,\%,\&</nnn>"
+-- Iteration 12 --
+string(75) "<nnn>I am a quoted (\") string with special chars like \$,\!,\@,\%,\&</nnn>"
+Done
diff --git a/ext/standard/tests/strings/strip_tags_variation8_binary.phpt b/ext/standard/tests/strings/strip_tags_variation8_binary.phpt
new file mode 100644 (file)
index 0000000..dbb582d
--- /dev/null
@@ -0,0 +1,59 @@
+--TEST--
+Test strip_tags() function : usage variations - valid value for 'str' and invalid values for 'allowable_tags', binary variant
+--INI--
+short_open_tag = on
+--FILE--
+<?php
+/* Prototype  : string strip_tags(string $str [, string $allowable_tags])
+ * Description: Strips HTML and PHP tags from a string
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * testing functionality of strip_tags() by giving valid value for $str and invalid values for $allowable_tags argument
+*/
+
+echo "*** Testing strip_tags() : usage variations ***\n";
+
+$strings = b"<html>hello</html> \tworld... <p>strip_tags_test\v\f</p><?php hello\t wo\rrld?>";
+
+$quotes = array (
+  b"<nnn>",
+  b'<nnn>',
+  b"<abc>",
+  b'<abc>',
+  b"<%?php",
+  b'<%?php',
+  b"<<html>>",
+  b'<<html>>'
+);
+
+//loop through the various elements of strings array to test strip_tags() functionality
+$iterator = 1;
+foreach($quotes as $string_value)
+{
+      echo "-- Iteration $iterator --\n";
+      var_dump( strip_tags($strings, $string_value) );
+      $iterator++;
+}
+
+echo "Done";
+--EXPECT--
+*** Testing strip_tags() : usage variations ***
+-- Iteration 1 --
+string(33) "hello      world... strip_tags_test\v\f"
+-- Iteration 2 --
+string(33) "hello      world... strip_tags_test\v\f"
+-- Iteration 3 --
+string(33) "hello      world... strip_tags_test\v\f"
+-- Iteration 4 --
+string(33) "hello      world... strip_tags_test\v\f"
+-- Iteration 5 --
+string(33) "hello      world... strip_tags_test\v\f"
+-- Iteration 6 --
+string(33) "hello      world... strip_tags_test\v\f"
+-- Iteration 7 --
+string(46) "<html>hello</html>         world... strip_tags_test\v\f"
+-- Iteration 8 --
+string(46) "<html>hello</html>         world... strip_tags_test\v\f"
+Done
diff --git a/ext/standard/tests/strings/strip_tags_variation9_binary.phpt b/ext/standard/tests/strings/strip_tags_variation9_binary.phpt
new file mode 100644 (file)
index 0000000..0e678a5
--- /dev/null
@@ -0,0 +1,56 @@
+--TEST--
+Test strip_tags() function : usage variations - double quoted strings, binary variant
+--INI--
+set short_open_tag = on
+--FILE--
+<?php
+/* Prototype  : string strip_tags(string $str [, string $allowable_tags])
+ * Description: Strips HTML and PHP tags from a string
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * testing functionality of strip_tags() by giving double quoted strings as values for $str argument
+*/
+
+echo "*** Testing strip_tags() : usage variations ***\n";
+
+$double_quote_string = array (
+  b"<html> \$ -> This represents the dollar sign</html><?php echo hello ?>",
+  b"<html>\t\r\v The quick brown fo\fx jumped over the lazy dog</p>",
+  b"<a>This is a hyper text tag</a>",
+  b"<? <html>hello world\\t</html>?>",
+  b"<p>This is a paragraph</p>",
+  b"<b>This is \ta text in bold letters\r\s\malong with slashes\n</b>"
+);
+
+$quotes = b"<html><a><p><b><?php";
+
+//loop through the various elements of strings array to test strip_tags() functionality
+$iterator = 1;
+foreach($double_quote_string as $string_value)
+{
+      echo "-- Iteration $iterator --\n";
+      var_dump( strip_tags($string_value, $quotes) );
+      $iterator++;
+}
+
+echo "Done";
+--EXPECT--
+*** Testing strip_tags() : usage variations ***
+-- Iteration 1 --
+string(50) "<html> $ -> This represents the dollar sign</html>"
+-- Iteration 2 --
+string(59) "<html>     
+\v The quick brown fo\fx jumped over the lazy dog</p>"
+-- Iteration 3 --
+string(31) "<a>This is a hyper text tag</a>"
+-- Iteration 4 --
+string(0) ""
+-- Iteration 5 --
+string(26) "<p>This is a paragraph</p>"
+-- Iteration 6 --
+string(62) "<b>This is         a text in bold letters
+\s\malong with slashes
+</b>"
+Done