File tree Expand file tree Collapse file tree 3 files changed +27
-6
lines changed Expand file tree Collapse file tree 3 files changed +27
-6
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Unreleased
4
4
5
- - HtmlFilter: < script > content should be filtered out.
5
+ ### Fixed
6
6
7
+ - HtmlFilter: <script > content should be filtered out.
8
+ - HtmlFilter: only for "keywords" and "description" meta tags "content" attr should be treated as
9
+ string.
7
10
8
11
## 1.7.1 - 2017-05-01
9
12
Original file line number Diff line number Diff line change @@ -64,6 +64,16 @@ class HtmlFilter implements Filter
64
64
'title '
65
65
];
66
66
67
+ /**
68
+ * Meta tag names with text content.
69
+ *
70
+ * @var string[]
71
+ */
72
+ static private $ textMetaTags = [
73
+ 'description ' ,
74
+ 'keywords '
75
+ ];
76
+
67
77
/**
68
78
* Filter string.
69
79
*
@@ -78,7 +88,7 @@ public function filter($string)
78
88
$ result = '' ;
79
89
80
90
$ string = $ this ->filterEntities ($ string );
81
- $ string = $ this ->filterHttpEquivMetaTags ($ string );
91
+ $ string = $ this ->filterMetaTags ($ string );
82
92
83
93
// Current/last tag name
84
94
$ tagName = null ;
@@ -208,18 +218,24 @@ function ($match) {
208
218
}
209
219
210
220
/**
211
- * Replace meta tags with HTTP header equivalents .
221
+ * Replace non-text meta tags.
212
222
*
213
223
* @param string $string
214
224
*
215
225
* @return string
216
226
*/
217
- private function filterHttpEquivMetaTags ($ string )
227
+ private function filterMetaTags ($ string )
218
228
{
219
229
return preg_replace_callback (
220
- '/<meta[^>]+http-equiv=[^>]+ >/i ' ,
230
+ '/<meta[^>]+( http-equiv\s*=|name\s*=\s*[" \' ]?([^>" \' ]+))[^>]* >/i ' ,
221
231
function ($ match ) {
222
- return str_repeat (' ' , strlen ($ match [0 ]));
232
+ if (count ($ match ) < 3
233
+ || !in_array (strtolower ($ match [2 ]), self ::$ textMetaTags , true )
234
+ ) {
235
+ return str_repeat (' ' , strlen ($ match [0 ]));
236
+ }
237
+
238
+ return $ match [0 ];
223
239
},
224
240
$ string
225
241
);
Original file line number Diff line number Diff line change @@ -39,10 +39,12 @@ public function testMetaContent()
39
39
$ html =
40
40
'<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html" /> ' . "\n" .
41
41
'<meta name="Keywords" content="Foo"> ' . "\n" .
42
+ '<meta name="foo" content="Foobar"> ' . "\n" .
42
43
'<meta name="description" content="Bar"> ' ;
43
44
$ text =
44
45
" \n" .
45
46
" Foo \n" .
47
+ " \n" .
46
48
' Bar ' ;
47
49
static ::assertEquals ($ text , $ filter ->filter ($ html ));
48
50
}
You can’t perform that action at this time.
0 commit comments