mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateStyles
synced 2024-12-17 18:40:37 +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 );
|
parent::__construct( $matcherFactory );
|
||||||
|
|
||||||
// Only allow the font-family if it begins with "TemplateStyles"
|
// Only allow the font-family if it begins with "TemplateStyles"
|
||||||
|
$validator = static fn ( Token $t ) => str_starts_with( $t->value(), 'TemplateStyles' );
|
||||||
$this->propertySanitizer->setKnownProperties( [
|
$this->propertySanitizer->setKnownProperties( [
|
||||||
'font-family' => new Alternative( [
|
'font-family' => new Alternative( [
|
||||||
new TokenMatcher( Token::T_STRING, static function ( Token $t ) {
|
new TokenMatcher( Token::T_STRING, $validator ),
|
||||||
return substr( $t->value(), 0, 14 ) === 'TemplateStyles';
|
|
||||||
} ),
|
|
||||||
new Juxtaposition( [
|
new Juxtaposition( [
|
||||||
new TokenMatcher( Token::T_IDENT, static function ( Token $t ) {
|
new TokenMatcher( Token::T_IDENT, $validator ),
|
||||||
return substr( $t->value(), 0, 14 ) === 'TemplateStyles';
|
|
||||||
} ),
|
|
||||||
Quantifier::star( $matcherFactory->ident() ),
|
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
|
// Don't allow unescaped \ or /../ in the non-query part of the URL
|
||||||
$tmp = preg_replace( '<[#?].*$>', '', $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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue