mirror of
https://github.com/php/php-src.git
synced 2024-12-12 03:15:29 +08:00
Merge branch 'PHP-7.1' into PHP-7.2
This commit is contained in:
commit
0504594a28
@ -176,12 +176,14 @@ typedef struct _php_strip_tags_filter {
|
||||
uint8_t persistent;
|
||||
} php_strip_tags_filter;
|
||||
|
||||
static int php_strip_tags_filter_ctor(php_strip_tags_filter *inst, const char *allowed_tags, size_t allowed_tags_len, int persistent)
|
||||
static int php_strip_tags_filter_ctor(php_strip_tags_filter *inst, zend_string *allowed_tags, int persistent)
|
||||
{
|
||||
if (allowed_tags != NULL) {
|
||||
inst->allowed_tags = pemalloc(allowed_tags_len, persistent);
|
||||
memcpy((char *)inst->allowed_tags, allowed_tags, allowed_tags_len);
|
||||
inst->allowed_tags_len = (int)allowed_tags_len;
|
||||
if (NULL == (inst->allowed_tags = pemalloc(ZSTR_LEN(allowed_tags) + 1, persistent))) {
|
||||
return FAILURE;
|
||||
}
|
||||
memcpy((char *)inst->allowed_tags, ZSTR_VAL(allowed_tags), ZSTR_LEN(allowed_tags) + 1);
|
||||
inst->allowed_tags_len = (int)ZSTR_LEN(allowed_tags);
|
||||
} else {
|
||||
inst->allowed_tags = NULL;
|
||||
}
|
||||
@ -245,12 +247,14 @@ static php_stream_filter_ops strfilter_strip_tags_ops = {
|
||||
static php_stream_filter *strfilter_strip_tags_create(const char *filtername, zval *filterparams, uint8_t persistent)
|
||||
{
|
||||
php_strip_tags_filter *inst;
|
||||
smart_str tags_ss = {0};
|
||||
php_stream_filter *filter = NULL;
|
||||
zend_string *allowed_tags = NULL;;
|
||||
|
||||
inst = pemalloc(sizeof(php_strip_tags_filter), persistent);
|
||||
|
||||
if (filterparams != NULL) {
|
||||
if (Z_TYPE_P(filterparams) == IS_ARRAY) {
|
||||
smart_str tags_ss = {0};
|
||||
zval *tmp;
|
||||
|
||||
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(filterparams), tmp) {
|
||||
@ -260,22 +264,23 @@ static php_stream_filter *strfilter_strip_tags_create(const char *filtername, zv
|
||||
smart_str_appendc(&tags_ss, '>');
|
||||
} ZEND_HASH_FOREACH_END();
|
||||
smart_str_0(&tags_ss);
|
||||
allowed_tags = tags_ss.s;
|
||||
} else {
|
||||
/* FIXME: convert_to_* may clutter zvals and lead it into segfault ? */
|
||||
convert_to_string_ex(filterparams);
|
||||
smart_str_setl(&tags_ss, Z_STRVAL_P(filterparams), Z_STRLEN_P(filterparams));
|
||||
allowed_tags = zval_get_string(filterparams);
|
||||
}
|
||||
}
|
||||
|
||||
if (php_strip_tags_filter_ctor(inst, ZSTR_VAL(tags_ss.s), ZSTR_LEN(tags_ss.s), persistent) != SUCCESS) {
|
||||
smart_str_free(&tags_ss);
|
||||
if (php_strip_tags_filter_ctor(inst, allowed_tags, persistent) == SUCCESS) {
|
||||
filter = php_stream_filter_alloc(&strfilter_strip_tags_ops, inst, persistent);
|
||||
} else {
|
||||
pefree(inst, persistent);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
smart_str_free(&tags_ss);
|
||||
if (allowed_tags) {
|
||||
zend_string_release(allowed_tags);
|
||||
}
|
||||
|
||||
return php_stream_filter_alloc(&strfilter_strip_tags_ops, inst, persistent);
|
||||
return filter;
|
||||
}
|
||||
|
||||
static php_stream_filter_factory strfilter_strip_tags_factory = {
|
||||
|
24
ext/standard/tests/filters/strip_tags_filter.phpt
Normal file
24
ext/standard/tests/filters/strip_tags_filter.phpt
Normal file
@ -0,0 +1,24 @@
|
||||
--TEST--
|
||||
string.strip_tags filter
|
||||
--FILE--
|
||||
<?php
|
||||
$fp = fopen('php://output', 'w');
|
||||
stream_filter_append($fp, 'string.strip_tags');
|
||||
fwrite($fp, "test <b>bold</b> <i>italic</i> test\n");
|
||||
fclose($fp);
|
||||
|
||||
$fp = fopen('php://output', 'w');
|
||||
stream_filter_append($fp, 'string.strip_tags', STREAM_FILTER_WRITE, "<b>");
|
||||
fwrite($fp, "test <b>bold</b> <i>italic</i> test\n");
|
||||
fclose($fp);
|
||||
|
||||
$fp = fopen('php://output', 'w');
|
||||
stream_filter_append($fp, 'string.strip_tags', STREAM_FILTER_WRITE, ["b"]);
|
||||
fwrite($fp, "test <b>bold</b> <i>italic</i> test\n");
|
||||
fclose($fp);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
test bold italic test
|
||||
test <b>bold</b> italic test
|
||||
test <b>bold</b> italic test
|
Loading…
Reference in New Issue
Block a user