Skip to content

Commit cd39bfd

Browse files
committed
Merge branch '3.1'
2 parents 3f085e0 + c3732e8 commit cd39bfd

File tree

4 files changed

+73
-13
lines changed

4 files changed

+73
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ This is a log of major user-visible changes in each phpMyFAQ release.
1515
- updated Japanese translation (Advanced Bear)
1616
-
1717

18-
### phpMyFAQ v3.1.3 - 2022-XX-XX
18+
### phpMyFAQ v3.1.3 - 2022-04-XX
1919

20+
- fixed login via LDAP or ActiveDirectory (Thorsten)
2021
- fixed minor bugs (Thorsten)
2122

2223
### phpMyFAQ v3.1.2 - 2022-03-16

phpmyfaq/src/phpMyFAQ/Filter.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,40 @@ public static function removeAttributes(string $html = ''): string
169169

170170
foreach ($attributes[0] as $attribute) {
171171
$attributeName = stristr($attribute, '=', true);
172-
if (!in_array($attributeName, $keep)) {
172+
if (self::isAttribute($attributeName) && !in_array($attributeName, $keep)) {
173173
$html = str_replace(' ' . $attribute, '', $html);
174174
}
175175
}
176176

177177
return $html;
178178
}
179+
180+
/**
181+
* @param string $attribute
182+
* @return bool
183+
*/
184+
private static function isAttribute(string $attribute): bool
185+
{
186+
$globalAttributes = [
187+
'autocomplete', 'autofocus', 'disabled', 'list', 'name', 'readonly', 'required', 'tabindex', 'type',
188+
'value', 'accesskey', 'class', 'contenteditable', 'contextmenu', 'dir', 'draggable', 'dropzone', 'id',
189+
'lang', 'style', 'tabindex', 'title', 'inputmode', 'is', 'itemid', 'itemprop', 'itemref', 'itemscope',
190+
'itemtype', 'lang', 'slot', 'spellcheck', 'translate', 'autofocus', 'disabled', 'form', 'multiple', 'name',
191+
'required', 'size', 'autocapitalize', 'autocomplete', 'autofocus', 'cols', 'disabled', 'form', 'maxlength',
192+
'minlength', 'name', 'placeholder', 'readonly', 'required', 'rows', 'spellcheck', 'wrap', 'onmouseenter',
193+
'onmouseleave', 'onafterprint', 'onbeforeprint', 'onbeforeunload', 'onhashchange', 'onmessage', 'onoffline',
194+
'ononline', 'onpopstate', 'onpagehide', 'onpageshow', 'onresize', 'onunload', 'ondevicemotion', 'preload',
195+
'ondeviceorientation', 'onabort', 'onblur', 'oncanplay', 'oncanplaythrough', 'onchange', 'onclick',
196+
'oncontextmenu', 'ondblclick', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover',
197+
'ondragstart', 'ondrop', 'ondurationchange', 'onemptied', 'onended', 'onerror', 'onfocus', 'oninput',
198+
'oninvalid', 'onkeydown', 'onkeypress', 'onkeyup', 'onload', 'onloadeddata', 'onloadedmetadata',
199+
'onloadstart', 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup','controls',
200+
'onmozfullscreenchange', 'onmozfullscreenerror', 'onpause', 'onplay', 'onplaying', 'onprogress',
201+
'onratechange', 'onreset', 'onscroll', 'onseeked', 'onseeking', 'onselect', 'onshow', 'onstalled',
202+
'onsubmit', 'onsuspend', 'ontimeupdate', 'onvolumechange', 'onwaiting', 'oncopy', 'oncut', 'onpaste',
203+
'onbeforescriptexecute', 'onafterscriptexecute'
204+
];
205+
206+
return in_array($attribute, $globalAttributes);
207+
}
179208
}

phpmyfaq/src/phpMyFAQ/Utils.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
88
* obtain one at https://mozilla.org/MPL/2.0/.
99
*
10-
* @package phpMyFAQ
10+
* @package phpMyFAQ
1111
* @author Thorsten Rinne <[email protected]>
1212
* @author Matteo Scaramuccia <[email protected]>
1313
* @copyright 2005-2022 phpMyFAQ Team
14-
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
15-
* @link https://www.phpmyfaq.de
16-
* @since 2005-11-01
14+
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
15+
* @link https://www.phpmyfaq.de
16+
* @since 2005-11-01
1717
*/
1818

1919
namespace phpMyFAQ;
@@ -185,9 +185,9 @@ public static function setHighlightedString(string $string, string $highlight):
185185
*/
186186
public static function highlightNoLinks(array $matches): string
187187
{
188-
$prefix = isset($matches[3]) ? $matches[3] : '';
189-
$item = isset($matches[4]) ? $matches[4] : '';
190-
$postfix = isset($matches[5]) ? $matches[5] : '';
188+
$prefix = $matches[3] ?? '';
189+
$item = $matches[4] ?? '';
190+
$postfix = $matches[5] ?? '';
191191

192192
if (!empty($item) && !self::isForbiddenElement($item)) {
193193
return sprintf(
@@ -260,13 +260,11 @@ public static function parseUrl(string $string): string
260260
$string = str_replace($protocols, '', $string);
261261
$string = str_replace('www.', 'http://www.', $string);
262262
$string = preg_replace('|http://([a-zA-Z0-9-\./]+)|', '<a href="http://$1">$1</a>', $string);
263-
$string = preg_replace(
263+
return preg_replace(
264264
'/(([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6})/',
265265
'<a href="mailto:$1">$1</a>',
266266
$string
267267
);
268-
269-
return $string;
270268
}
271269

272270
/**

tests/phpMyFAQ/FilterTest.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
<?php
22

3+
/**
4+
* Test suite for Filter class
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public License,
7+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
8+
* obtain one at https://mozilla.org/MPL/2.0/.
9+
*
10+
* @package phpMyFAQ
11+
* @author Thorsten Rinne <[email protected]>
12+
* @copyright 2022 phpMyFAQ Team
13+
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14+
* @link https://www.phpmyfaq.de
15+
* @since 2022-04-08
16+
*/
17+
318
namespace phpMyFAQ;
419

520
use PHPUnit\Framework\TestCase;
621

722
/**
8-
*
923
* @testdox Filter should
1024
*/
1125
class FilterTest extends TestCase
@@ -49,5 +63,23 @@ public function testRemoveAttributes(): void
4963
{
5064
$this->assertEquals('<video />', Filter::removeAttributes('<video preload="auto" />'));
5165
$this->assertEquals('<video controls />', Filter::removeAttributes('<video controls />'));
66+
67+
$expected = '<a href="#">phpMyFAQ</a>';
68+
$actual = Filter::removeAttributes($expected);
69+
$this->assertEquals($expected, $actual);
70+
71+
$expected = '<a href="#">phpMyFAQ</a>';
72+
$toTest = '<a href="#" onchange="bar()">phpMyFAQ</a>';
73+
$actual = Filter::removeAttributes($toTest);
74+
$this->assertEquals($expected, $actual);
75+
76+
$expected = '<a href="#">phpMyFAQ</a>';
77+
$toTest = '<a href="#" disabled="disabled">phpMyFAQ</a>';
78+
$actual = Filter::removeAttributes($toTest);
79+
$this->assertEquals($expected, $actual);
80+
81+
$expected = 'To: sslEnabledProtocols="TLSv1.2"';
82+
$actual = Filter::removeAttributes($expected);
83+
$this->assertEquals($expected, $actual);
5284
}
5385
}

0 commit comments

Comments
 (0)