From fd2b75ab78c3af652d95037b5f4e7e06d20c906b Mon Sep 17 00:00:00 2001 From: manuwhat Date: Sat, 22 Jun 2019 13:01:19 +0200 Subject: [PATCH] fix issues --- .php_cs.cache | 1 + README.md | 6 +++--- htmlstriptestinBrowser.php | 28 ++++++++++++++++++++++++++++ src/beforeStrip.php | 7 ++++--- src/htmlStripHelper.php | 4 ++-- src/prepareStrip.php | 4 ++-- tests/htmlStripTest.php | 2 +- 7 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 .php_cs.cache create mode 100644 htmlstriptestinBrowser.php diff --git a/.php_cs.cache b/.php_cs.cache new file mode 100644 index 0000000..ee4bb1b --- /dev/null +++ b/.php_cs.cache @@ -0,0 +1 @@ +{"php":"7.1.3","version":"2.14.2:v2.14.2#ff401e58261ffc5934a58f795b3f95b355e276cb","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true},"hashes":{"src\\DOMNodeRecursiveIterator.php":-686522259,"src\\htmlStrip.php":-2048634141,"src\\beforeStrip.php":-91041789,"src\\prepareStrip.php":64860972,"tests\\NamedArgsTest.php":254555693,"src\\htmlstripHelper.php":1910840005,"tests\\htmlStripTest.php":2020517432,"src\\htmlStripHelper.php":1393751100,"htmlstriptestinBrowser.php":-70126872}} \ No newline at end of file diff --git a/README.md b/README.md index 850c000..5315b9b 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ Strip-tags ========== + +remove PHP and HTML Tags from a string in a custom and efficient way + [![Build Status](https://travis-ci.org/manuwhat/strip-tags.svg?branch=master)](https://travis-ci.org/manuwhat/strip-tags) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/manuwhat/strip-tags/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/manuwhat/strip-tags/?branch=master) [![Build Status](https://scrutinizer-ci.com/g/manuwhat/strip-tags/badges/build.png?b=master)](https://scrutinizer-ci.com/g/manuwhat/strip-tags/build-status/master) [![Code Intelligence Status](https://scrutinizer-ci.com/g/manuwhat/strip-tags/badges/code-intelligence.svg?b=master)](https://scrutinizer-ci.com/code-intelligence) -remove PHP and HTML Tags from a string in a custom and efficient way - - **Requires**: PHP 5.3+ diff --git a/htmlstriptestinBrowser.php b/htmlstriptestinBrowser.php new file mode 100644 index 0000000..1cec440 --- /dev/null +++ b/htmlstriptestinBrowser.php @@ -0,0 +1,28 @@ +'; +$data='aaaaa'.$x.'

u

a

b2b2 '; + +$hstrip=new htmlStrip($data, 'replace', array('

',false)); +var_dump($hstrip->go()===strip_tags($data, '

'));//true + + +$hstrip=new htmlStrip($data); +var_dump($hstrip->go()===strip_tags($data));//true + +$hstrip=new htmlStrip($data, 'replace', array('',true), array('src',true)); +var_dump((bool)stripos($hstrip->go(htmlStrip::ATTRIBUTES), 'src'));//false + +$hstrip=new htmlStrip($data, 'replace', array('',true), array('src',false)); +var_dump((bool)stripos($hstrip->go(htmlStrip::ATTRIBUTES), 'type'));//false +var_dump((bool)stripos($hstrip->go(htmlStrip::ATTRIBUTES), 'src'),htmlspecialchars($hstrip->go(htmlStrip::ATTRIBUTES)));//true; + + diff --git a/src/beforeStrip.php b/src/beforeStrip.php index 7f6b9bc..72d864c 100644 --- a/src/beforeStrip.php +++ b/src/beforeStrip.php @@ -22,12 +22,13 @@ public function __construct($html) $html='
'.str_replace( array($this->doctype, $this->html_tag, '', $this->head, '', $this->body, ''), - array('doctype, 10), 'html_tag, 5), '', 'head, 5), '', 'body, 5), ''), + array('doctype, 9), 'html_tag, 5), '', 'head, 5), '', 'body, 5), ''), $html ).'
'; + $preprocessed=token_get_all($html); - $HTML=array_filter($preprocessed, function($v) { + $HTML=array_filter($preprocessed, function ($v) { return is_array($v)&&$v[0]===T_INLINE_HTML; }); $PHP=array_diff_key($preprocessed, $HTML); @@ -36,7 +37,7 @@ public function __construct($html) protected function setMainTags(&$html) { - $doctypeOffset=stripos($html, '','',''])) { diff --git a/src/prepareStrip.php b/src/prepareStrip.php index cc607a6..27f1cb8 100644 --- a/src/prepareStrip.php +++ b/src/prepareStrip.php @@ -26,13 +26,13 @@ public function getPrepared() public function prepareHtml() { - return array_map(function($v) { + return array_map(function ($v) { return is_array($v) ? $v[1] : $v; }, $this->prepocessed->getHTML()); } public function preparePhp() { - return array_map(function($v) { + return array_map(function ($v) { return is_array($v)&&($v[0]===T_OPEN_TAG||$v[0]===T_CLOSE_TAG) ? ($v[0]===T_OPEN_TAG ? '' : '') : (is_array($v) ? $v[1] : $v); }, $this->prepocessed->getPHP()); } diff --git a/tests/htmlStripTest.php b/tests/htmlStripTest.php index 2f682b8..601b857 100644 --- a/tests/htmlStripTest.php +++ b/tests/htmlStripTest.php @@ -28,7 +28,7 @@ public function testGo() $this->assertFalse((bool)stripos($hstrip->go(htmlStrip::ATTRIBUTES), 'src')); $hstrip=new htmlStrip($data, 'replace', array('',true), array('src',false)); - $this->assertFalse((bool)stripos($hstrip->go(htmlStrip::ATTRIBUTES), 'type')); + $this->assertFalse((bool)stripos($hstrip->go(htmlStrip::ATTRIBUTES), ' type')); $this->assertTrue((bool)stripos($hstrip->go(htmlStrip::ATTRIBUTES), 'src')); } }