Patch Add-strip_tags-third-optional-parameter for Filter related Bug #62032
Patch version 2012-05-15 14:26 UTC
Return to Bug #62032 |
Download this patch
Patch Revisions:
Developer: reeze.xia@gmail.com
From f9b80a74ba7bc6e9659881d4c6fac18aeb533356 Mon Sep 17 00:00:00 2001
From: Reeze Xia <reeze.xia@gmail.com>
Date: Tue, 15 May 2012 22:23:54 +0800
Subject: [PATCH] Add strip_tags() third optional parameter to strip tags with
space
Signed-off-by: Reeze Xia <reeze.xia@gmail.com>
---
ext/standard/string.c | 13 ++++---
.../tests/strings/strip_tags_variation12.phpt | 41 ++++++++++++++++++++
2 files changed, 48 insertions(+), 6 deletions(-)
create mode 100644 ext/standard/tests/strings/strip_tags_variation12.phpt
diff --git a/ext/standard/string.c b/ext/standard/string.c
index 5c33232..d4ba846 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -4069,19 +4069,20 @@ PHP_FUNCTION(nl2br)
}
/* }}} */
-/* {{{ proto string strip_tags(string str [, string allowable_tags])
+/* {{{ proto string strip_tags(string str [, string allowable_tags = null [, bool allow_tag_spaces = false]])
Strips HTML and PHP tags from a string */
PHP_FUNCTION(strip_tags)
{
char *buf;
char *str;
- zval **allow=NULL;
- char *allowed_tags=NULL;
- int allowed_tags_len=0;
+ zval **allow = NULL;
+ char *allowed_tags = NULL;
+ int allowed_tags_len = 0;
+ zend_bool allow_tag_spaces = 0;
int str_len;
size_t retval_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|Z", &str, &str_len, &allow) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|Zb", &str, &str_len, &allow, &allow_tag_spaces) == FAILURE) {
return;
}
@@ -4093,7 +4094,7 @@ PHP_FUNCTION(strip_tags)
}
buf = estrndup(str, str_len);
- retval_len = php_strip_tags_ex(buf, str_len, NULL, allowed_tags, allowed_tags_len, 0);
+ retval_len = php_strip_tags_ex(buf, str_len, NULL, allowed_tags, allowed_tags_len, allow_tag_spaces);
RETURN_STRINGL(buf, retval_len, 0);
}
/* }}} */
diff --git a/ext/standard/tests/strings/strip_tags_variation12.phpt b/ext/standard/tests/strings/strip_tags_variation12.phpt
new file mode 100644
index 0000000..5d5725f
--- /dev/null
+++ b/ext/standard/tests/strings/strip_tags_variation12.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Test strip_tags() function : allow tag spaces
+--INI--
+short_open_tag = on
+--FILE--
+<?php
+
+echo "*** Testing strip_tags() : allow tag spaces ***\n";
+
+// array of arguments
+$string_array = array (
+ 'hello < img title="<"> world',
+ 'hello < img title=">"> world',
+ 'hello < < < img title=">_<" world',
+ "hello < <> <\timg 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, null, true) );
+ $iteration++;
+}
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing strip_tags() : allow tag spaces ***
+-- Iteration 1 --
+string(12) "hello world"
+-- Iteration 2 --
+string(12) "hello world"
+-- Iteration 3 --
+string(6) "hello "
+-- Iteration 4 --
+string(6) "hello "
+Done
--
1.7.9.3
|