Skip to content

Commit f85eea6

Browse files
committed
Added Smarty flag for paquettg#184
1 parent 77de30f commit f85eea6

File tree

5 files changed

+53
-14
lines changed

5 files changed

+53
-14
lines changed

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
### Development
22

3-
## 1.2.0
3+
All notable changes to this project will be documented in this file.
44

5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
- New `removeSmartyScripts` configuration setting. Defaults to true.
12+
13+
### Changed
14+
- Started using a changelog.
515
- Fixed bug that caused an infinite loop when no content found in tags.

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,12 @@ Preserves Line Breaks if set to `true`. If set to `false` line breaks are cleane
170170

171171
**removeDoubleSpace**
172172

173-
Set this to `false` if you want to preserver whitespace inside of text nodes. It is set to `true` by default.
173+
Set this to `false` if you want to preserve whitespace inside of text nodes. It is set to `true` by default.
174+
175+
**removeSmartyScripts**
176+
177+
Set this to `false` if you want to preserve smarty sccript found in the html content. It is set to `true` by default.
178+
174179
Static Facade
175180
-------------
176181

src/PHPHtmlParser/Dom.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,24 +502,26 @@ protected function clean(string $str): string
502502
$str = mb_eregi_replace("<!\[CDATA\[(.*?)\]\]>", '', $str);
503503

504504
// strip out <script> tags
505-
if ($this->options->get('removeScripts') == true) {
505+
if ($this->options->get('removeScripts')) {
506506
$str = mb_eregi_replace("<\s*script[^>]*[^/]>(.*?)<\s*/\s*script\s*>", '', $str);
507507
$str = mb_eregi_replace("<\s*script\s*>(.*?)<\s*/\s*script\s*>", '', $str);
508508
}
509509

510510
// strip out <style> tags
511-
if ($this->options->get('removeStyles') == true) {
511+
if ($this->options->get('removeStyles')) {
512512
$str = mb_eregi_replace("<\s*style[^>]*[^/]>(.*?)<\s*/\s*style\s*>", '', $str);
513513
$str = mb_eregi_replace("<\s*style\s*>(.*?)<\s*/\s*style\s*>", '', $str);
514514
}
515515

516516
// strip out server side scripts
517-
if ($this->options->get('serverSideScriptis') == true){
517+
if ($this->options->get('serverSideScripts')) {
518518
$str = mb_eregi_replace("(<\?)(.*?)(\?>)", '', $str);
519519
}
520520

521521
// strip smarty scripts
522-
$str = mb_eregi_replace("(\{\w)(.*?)(\})", '', $str);
522+
if ($this->options->get('removeSmartyScripts')) {
523+
$str = mb_eregi_replace("(\{\w)(.*?)(\})", '', $str);
524+
}
523525

524526
return $str;
525527
}

src/PHPHtmlParser/Options.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @property bool removeStyles
1414
* @property bool preserveLineBreaks
1515
* @property bool removeDoubleSpace
16+
* @property bool removeSmartyScripts
1617
*/
1718
class Options
1819
{
@@ -23,14 +24,15 @@ class Options
2324
* @param array
2425
*/
2526
protected $defaults = [
26-
'whitespaceTextNode' => true,
27-
'strict' => false,
28-
'enforceEncoding' => null,
29-
'cleanupInput' => true,
30-
'removeScripts' => true,
31-
'removeStyles' => true,
32-
'preserveLineBreaks' => false,
33-
'removeDoubleSpace' => true,
27+
'whitespaceTextNode' => true,
28+
'strict' => false,
29+
'enforceEncoding' => null,
30+
'cleanupInput' => true,
31+
'removeScripts' => true,
32+
'removeStyles' => true,
33+
'preserveLineBreaks' => false,
34+
'removeDoubleSpace' => true,
35+
'removeSmartyScripts' => true,
3436
];
3537

3638
/**

tests/Options/CleanupTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,24 @@ public function testRemoveScriptsFalse()
7272
$dom->find('script')->getAttribute('type'));
7373
}
7474

75+
public function testSmartyScripts()
76+
{
77+
$dom = new Dom;
78+
$dom->load('
79+
aa={123}
80+
');
81+
$this->assertEquals(' aa= ', $dom->innerHtml);
82+
}
83+
84+
public function testSmartyScriptsDisabled()
85+
{
86+
$dom = new Dom;
87+
$dom->setOptions([
88+
'removeSmartyScripts' => false
89+
]);
90+
$dom->load('
91+
aa={123}
92+
');
93+
$this->assertEquals(' aa={123} ', $dom->innerHtml);
94+
}
7595
}

0 commit comments

Comments
 (0)