mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateStyles
synced 2024-11-24 00:06:06 +00:00
Use native str_contains and such where possible
I think this makes this code much easier to read. Change-Id: I0e4c0c8e4b9e32d1e612575ee136c89f0491c9c4
This commit is contained in:
parent
8642b5fcb5
commit
736a93a92e
|
@ -27,15 +27,12 @@ class TemplateStylesFontFaceAtRuleSanitizer extends FontFaceAtRuleSanitizer {
|
|||
parent::__construct( $matcherFactory );
|
||||
|
||||
// Only allow the font-family if it begins with "TemplateStyles"
|
||||
$validator = static fn ( Token $t ) => str_starts_with( $t->value(), 'TemplateStyles' );
|
||||
$this->propertySanitizer->setKnownProperties( [
|
||||
'font-family' => new Alternative( [
|
||||
new TokenMatcher( Token::T_STRING, static function ( Token $t ) {
|
||||
return substr( $t->value(), 0, 14 ) === 'TemplateStyles';
|
||||
} ),
|
||||
new TokenMatcher( Token::T_STRING, $validator ),
|
||||
new Juxtaposition( [
|
||||
new TokenMatcher( Token::T_IDENT, static function ( Token $t ) {
|
||||
return substr( $t->value(), 0, 14 ) === 'TemplateStyles';
|
||||
} ),
|
||||
new TokenMatcher( Token::T_IDENT, $validator ),
|
||||
Quantifier::star( $matcherFactory->ident() ),
|
||||
] ),
|
||||
] ),
|
||||
|
|
|
@ -46,7 +46,7 @@ class TemplateStylesMatcherFactory extends \Wikimedia\CSS\Grammar\MatcherFactory
|
|||
|
||||
// Don't allow unescaped \ or /../ in the non-query part of the URL
|
||||
$tmp = preg_replace( '<[#?].*$>', '', $url );
|
||||
if ( strpos( $tmp, '\\' ) !== false || preg_match( '<(?:^|/|%2[fF])\.+(?:/|%2[fF]|$)>', $tmp ) ) {
|
||||
if ( str_contains( $tmp, '\\' ) || preg_match( '<(?:^|/|%2[fF])\.+(?:/|%2[fF]|$)>', $tmp ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue