css-sanitizer
Classes to parse and sanitize CSS
Loading...
Searching...
No Matches
Wikimedia\CSS\Grammar\MatcherFactory Class Reference

Factory for predefined Grammar matchers. More...

Public Member Functions

 optionalWhitespace ()
 Matcher for optional whitespace.
 
 significantWhitespace ()
 Matcher for required whitespace.
 
 comma ()
 Matcher for a comma.
 
 ident ()
 Matcher for an arbitrary identifier.
 
 customIdent (array $exclude=[])
 Matcher for a <custom-ident>
 
 string ()
 Matcher for a string.
 
 urlstring ( $type)
 Matcher for a string containing a URL.
 
 url ( $type)
 Matcher for a URL.
 
 cssWideKeywords ()
 CSS-wide value keywords.
 
 calc (Matcher $typeMatcher, $type)
 Add calc() support to a basic type matcher.
 
 colorHex ()
 
 integer ()
 Matcher for an integer value.
 
 rawNumber ()
 Matcher for a real number, without calc()
 
 number ()
 Matcher for a real number.
 
 rawPercentage ()
 Matcher for a percentage value, without calc()
 
 percentage ()
 Matcher for a percentage value.
 
 lengthPercentage ()
 Matcher for a length-percentage value.
 
 frequencyPercentage ()
 Matcher for a frequency-percentage value.
 
 anglePercentage ()
 Matcher for an angle-percentage value.
 
 timePercentage ()
 Matcher for a time-percentage value.
 
 numberPercentage ()
 Matcher for a number-percentage value.
 
 dimension ()
 Matcher for a dimension value.
 
 zero ()
 Matches the number 0.
 
 length ()
 Matcher for a length value.
 
 angle ()
 Matcher for an angle value.
 
 time ()
 Matcher for a duration (time) value.
 
 frequency ()
 Matcher for a frequency value.
 
 resolution ()
 Matcher for a resolution value.
 
 safeColor ()
 Matcher for a color value, not including a custom property reference.
 
 color ()
 Matcher for a color value, including a possible custom property reference.
 
 image ()
 Matcher for an image value.
 
 position ()
 Matcher for a position value.
 
 bgPosition ()
 Matcher for a bg-position value.
 
 cssMediaQuery ( $strict=true)
 Matcher for a CSS media query.
 
 cssMediaQueryList ( $strict=true)
 Matcher for a CSS media query list.
 
 cssSupportsCondition (PropertySanitizer $declarationSanitizer=null, $strict=true)
 Matcher for a "supports-condition".
 
 cssDeclaration (PropertySanitizer $declarationSanitizer=null)
 Matcher for a declaration.
 
 cssSingleEasingFunction ()
 Matcher for single easing functions from CSS Easing Functions Level 1.
 

Static Public Member Functions

static singleton ()
 Return a static instance of the factory.
 

Protected Member Functions

 calcInternal (Matcher $typeMatcher, $type)
 
 rawInteger ()
 Matcher for an integer value, without calc()
 
 rawLength ()
 Matcher for a length value, without calc()
 
 rawAngle ()
 Matcher for an angle value, without calc()
 
 rawTime ()
 Matcher for a duration (time) value, without calc()
 
 rawFrequency ()
 Matcher for a frequency value, without calc()
 
 colorFuncs ()
 Matchers for color functions.
 

Protected Attributes

 $cache = []
 

Static Protected Attributes

static $lengthUnits
 
static $angleUnits = [ 'deg', 'grad', 'rad', 'turn' ]
 
static $timeUnits = [ 's', 'ms' ]
 
static $frequencyUnits = [ 'Hz', 'kHz' ]
 

CSS Selectors Level 3

https://www.w3.org/TR/2018/REC-selectors-3-20181106/#w3cselgrammar

 cssSelectorList ()
 List of selectors (selectors_group)
 
 cssSelector ()
 A single selector (selector)
 
 cssCombinator ()
 A CSS combinator (combinator)
 
 cssSimpleSelectorSeq ()
 A simple selector sequence (simple_selector_sequence)
 
 cssTypeSelector ()
 A type selector, i.e.
 
 cssNamespacePrefix ()
 A namespace prefix (namespace_prefix)
 
 cssUniversal ()
 The universal selector (universal)
 
 cssID ()
 An ID selector.
 
 cssClass ()
 A class selector (class)
 
 cssAttrib ()
 An attribute selector (attrib)
 
 cssPseudo ()
 A pseudo-class or pseudo-element (pseudo)
 
 cssANplusB ()
 An "AN+B" form.
 
 cssNegation ()
 A negation (negation)
 
 colorWords ()
 

Detailed Description

Factory for predefined Grammar matchers.

Note
For security, the attr() and var() functions are not supported, although as a limited exception var() is allowed for color attributes in ::colorFuncs().

Member Function Documentation

◆ angle()

Wikimedia\CSS\Grammar\MatcherFactory::angle ( )

Matcher for an angle value.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#angles
Returns
Matcher

◆ anglePercentage()

Wikimedia\CSS\Grammar\MatcherFactory::anglePercentage ( )

Matcher for an angle-percentage value.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#typedef-angle-percentage
Returns
Matcher

◆ bgPosition()

Wikimedia\CSS\Grammar\MatcherFactory::bgPosition ( )

Matcher for a bg-position value.

See also
https://www.w3.org/TR/2017/CR-css-backgrounds-3-20171017/#typedef-bg-position
Returns
Matcher

◆ calc()

Wikimedia\CSS\Grammar\MatcherFactory::calc ( Matcher $typeMatcher,
$type )

Add calc() support to a basic type matcher.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#calc-notation
Parameters
Matcher$typeMatcherMatcher for the type
string$typeType being matched
Returns
Matcher

◆ calcInternal()

Wikimedia\CSS\Grammar\MatcherFactory::calcInternal ( Matcher $typeMatcher,
$type )
protected
See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#calc-notation
Parameters
Matcher$typeMatcherMatcher for the type
string$typeType being matched
Returns
Matcher[]

◆ color()

Wikimedia\CSS\Grammar\MatcherFactory::color ( )

Matcher for a color value, including a possible custom property reference.

See also
https://www.w3.org/TR/2018/REC-css-color-3-20180619/#colorunits
Returns
Matcher

◆ colorFuncs()

Wikimedia\CSS\Grammar\MatcherFactory::colorFuncs ( )
protected

Matchers for color functions.

Returns
Matcher[]

◆ colorHex()

Wikimedia\CSS\Grammar\MatcherFactory::colorHex ( )
Returns
TokenMatcher

◆ colorWords()

Wikimedia\CSS\Grammar\MatcherFactory::colorWords ( )
Returns
KeywordMatcher

◆ comma()

Wikimedia\CSS\Grammar\MatcherFactory::comma ( )

Matcher for a comma.

Returns
Matcher

◆ cssANplusB()

Wikimedia\CSS\Grammar\MatcherFactory::cssANplusB ( )

◆ cssAttrib()

Wikimedia\CSS\Grammar\MatcherFactory::cssAttrib ( )

An attribute selector (attrib)

'[' S* [ namespace_prefix ]? IDENT S*
    [ [ PREFIXMATCH |
        SUFFIXMATCH |
        SUBSTRINGMATCH |
        '=' |
        INCLUDES |
        DASHMATCH ] S* [ IDENT | STRING ] S*
    ]? ']'

Captures are set for the attribute, test, and value. Note that these captures will probably be relative to the contents of the SimpleBlock that this matcher matches!

Returns
Matcher

◆ cssClass()

Wikimedia\CSS\Grammar\MatcherFactory::cssClass ( )

A class selector (class)

'.' IDENT
Returns
Matcher

◆ cssCombinator()

Wikimedia\CSS\Grammar\MatcherFactory::cssCombinator ( )

A CSS combinator (combinator)

PLUS S* | GREATER S* | TILDE S* | S+

(combinators can be surrounded by whitespace)

Returns
Matcher

◆ cssDeclaration()

Wikimedia\CSS\Grammar\MatcherFactory::cssDeclaration ( PropertySanitizer $declarationSanitizer = null)

Matcher for a declaration.

Parameters
PropertySanitizer | null$declarationSanitizerCheck declarations against this Sanitizer
Returns
Matcher

◆ cssID()

Wikimedia\CSS\Grammar\MatcherFactory::cssID ( )

An ID selector.

HASH
Returns
Matcher

◆ cssMediaQuery()

Wikimedia\CSS\Grammar\MatcherFactory::cssMediaQuery ( $strict = true)

Matcher for a CSS media query.

See also
https://www.w3.org/TR/2017/CR-mediaqueries-4-20170905/#mq-syntax
Parameters
bool$strictOnly allow defined query types
Returns
Matcher

◆ cssMediaQueryList()

Wikimedia\CSS\Grammar\MatcherFactory::cssMediaQueryList ( $strict = true)

Matcher for a CSS media query list.

See also
https://www.w3.org/TR/2017/CR-mediaqueries-4-20170905/#mq-syntax
Parameters
bool$strictOnly allow defined query types
Returns
Matcher

◆ cssNamespacePrefix()

Wikimedia\CSS\Grammar\MatcherFactory::cssNamespacePrefix ( )

A namespace prefix (namespace_prefix)

 [ IDENT | '*' ]? '|'
Returns
Matcher

◆ cssNegation()

Wikimedia\CSS\Grammar\MatcherFactory::cssNegation ( )

A negation (negation)

':' not( S* [ type_selector | universal | HASH | class | attrib | pseudo ] S* ')'
Returns
Matcher

◆ cssPseudo()

Wikimedia\CSS\Grammar\MatcherFactory::cssPseudo ( )

A pseudo-class or pseudo-element (pseudo)

':' ':'? [ IDENT | functional_pseudo ]

Where functional_pseudo is

FUNCTION S* expression ')'

Although this actually only matches the pseudo-selectors defined in the following sources:

Returns
Matcher

◆ cssSelector()

Wikimedia\CSS\Grammar\MatcherFactory::cssSelector ( )

A single selector (selector)

simple_selector_sequence [ combinator simple_selector_sequence ]*

Capturing is set up for the simple_selector_sequences (as 'simple') and combinator.

Returns
Matcher

◆ cssSelectorList()

Wikimedia\CSS\Grammar\MatcherFactory::cssSelectorList ( )

List of selectors (selectors_group)

selector [ COMMA S* selector ]*

Capturing is set up for the selectors.

Returns
Matcher

◆ cssSimpleSelectorSeq()

Wikimedia\CSS\Grammar\MatcherFactory::cssSimpleSelectorSeq ( )

A simple selector sequence (simple_selector_sequence)

[ type_selector | universal ]
[ HASH | class | attrib | pseudo | negation ]*
| [ HASH | class | attrib | pseudo | negation ]+

The following captures are set:

  • element: [ type_selector | universal ]
  • id: HASH
  • class: class
  • attrib: attrib
  • pseudo: pseudo
  • negation: negation
Returns
Matcher

◆ cssSingleEasingFunction()

Wikimedia\CSS\Grammar\MatcherFactory::cssSingleEasingFunction ( )

Matcher for single easing functions from CSS Easing Functions Level 1.

See also
https://www.w3.org/TR/2019/CR-css-easing-1-20190430/#typedef-easing-function
Returns
Matcher

◆ cssSupportsCondition()

Wikimedia\CSS\Grammar\MatcherFactory::cssSupportsCondition ( PropertySanitizer $declarationSanitizer = null,
$strict = true )

Matcher for a "supports-condition".

See also
https://www.w3.org/TR/2013/CR-css3-conditional-20130404/#supports_condition
Parameters
PropertySanitizer | null$declarationSanitizerCheck declarations against this Sanitizer
bool$strictOnly accept defined syntax. Default true.
Returns
Matcher

◆ cssTypeSelector()

Wikimedia\CSS\Grammar\MatcherFactory::cssTypeSelector ( )

A type selector, i.e.

a tag name (type_selector)

[ namespace_prefix ] ? element_name

where element_name is

IDENT
Returns
Matcher

◆ cssUniversal()

Wikimedia\CSS\Grammar\MatcherFactory::cssUniversal ( )

The universal selector (universal)

[ namespace_prefix ]? '*'
Returns
Matcher

◆ cssWideKeywords()

Wikimedia\CSS\Grammar\MatcherFactory::cssWideKeywords ( )

CSS-wide value keywords.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#common-keywords
Returns
Matcher

◆ customIdent()

Wikimedia\CSS\Grammar\MatcherFactory::customIdent ( array $exclude = [])

Matcher for a <custom-ident>

Note this doesn't implement the semantic restriction about assigning meaning to various idents in a complex value, as CSS Sanitizer doesn't deal with semantics on that level.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#identifier-value
Parameters
string[]$excludeAdditional values to exclude, all-lowercase.
Returns
Matcher

◆ dimension()

Wikimedia\CSS\Grammar\MatcherFactory::dimension ( )

Matcher for a dimension value.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#dimensions
Returns
Matcher

◆ frequency()

Wikimedia\CSS\Grammar\MatcherFactory::frequency ( )

Matcher for a frequency value.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#frequency
Returns
Matcher

◆ frequencyPercentage()

Wikimedia\CSS\Grammar\MatcherFactory::frequencyPercentage ( )

Matcher for a frequency-percentage value.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#typedef-frequency-percentage
Returns
Matcher

◆ ident()

Wikimedia\CSS\Grammar\MatcherFactory::ident ( )

Matcher for an arbitrary identifier.

Returns
Matcher

◆ image()

Wikimedia\CSS\Grammar\MatcherFactory::image ( )

Matcher for an image value.

See also
https://www.w3.org/TR/2019/CR-css-images-3-20191010/#image-values
Returns
Matcher

◆ integer()

Wikimedia\CSS\Grammar\MatcherFactory::integer ( )

Matcher for an integer value.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#integers
Returns
Matcher

◆ length()

Wikimedia\CSS\Grammar\MatcherFactory::length ( )

Matcher for a length value.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#lengths
Returns
Matcher

◆ lengthPercentage()

Wikimedia\CSS\Grammar\MatcherFactory::lengthPercentage ( )

Matcher for a length-percentage value.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#typedef-length-percentage
Returns
Matcher

◆ number()

Wikimedia\CSS\Grammar\MatcherFactory::number ( )

Matcher for a real number.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#numbers
Returns
Matcher

◆ numberPercentage()

Wikimedia\CSS\Grammar\MatcherFactory::numberPercentage ( )

Matcher for a number-percentage value.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#typedef-number-percentage
Returns
Matcher

◆ optionalWhitespace()

Wikimedia\CSS\Grammar\MatcherFactory::optionalWhitespace ( )

Matcher for optional whitespace.

Returns
Matcher

◆ percentage()

Wikimedia\CSS\Grammar\MatcherFactory::percentage ( )

Matcher for a percentage value.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#percentages
Returns
Matcher

◆ position()

Wikimedia\CSS\Grammar\MatcherFactory::position ( )

Matcher for a position value.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#typedef-position
Returns
Matcher

◆ rawAngle()

Wikimedia\CSS\Grammar\MatcherFactory::rawAngle ( )
protected

Matcher for an angle value, without calc()

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#angles
Returns
Matcher

◆ rawFrequency()

Wikimedia\CSS\Grammar\MatcherFactory::rawFrequency ( )
protected

Matcher for a frequency value, without calc()

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#frequency
Returns
Matcher

◆ rawInteger()

Wikimedia\CSS\Grammar\MatcherFactory::rawInteger ( )
protected

Matcher for an integer value, without calc()

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#integers
Returns
Matcher

◆ rawLength()

Wikimedia\CSS\Grammar\MatcherFactory::rawLength ( )
protected

Matcher for a length value, without calc()

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#lengths
Returns
Matcher

◆ rawNumber()

Wikimedia\CSS\Grammar\MatcherFactory::rawNumber ( )

Matcher for a real number, without calc()

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#numbers
Returns
Matcher

◆ rawPercentage()

Wikimedia\CSS\Grammar\MatcherFactory::rawPercentage ( )

Matcher for a percentage value, without calc()

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#percentages
Returns
Matcher

◆ rawTime()

Wikimedia\CSS\Grammar\MatcherFactory::rawTime ( )
protected

Matcher for a duration (time) value, without calc()

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#time
Returns
Matcher

◆ resolution()

Wikimedia\CSS\Grammar\MatcherFactory::resolution ( )

Matcher for a resolution value.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#resolution
Returns
Matcher

◆ safeColor()

Wikimedia\CSS\Grammar\MatcherFactory::safeColor ( )

Matcher for a color value, not including a custom property reference.

Because custom properties can lead to unexpected behavior (generally a bad thing for security) when concatenated together, this matcher should be used for CSS rules which allow value concatenation. For example, border-color allows up to 4 var(...) expressions to potentially be concatenated.

See also
https://www.w3.org/TR/2022/CR-css-variables-1-20220616/#custom-property
Returns
Matcher

◆ significantWhitespace()

Wikimedia\CSS\Grammar\MatcherFactory::significantWhitespace ( )

Matcher for required whitespace.

Returns
Matcher

◆ singleton()

static Wikimedia\CSS\Grammar\MatcherFactory::singleton ( )
static

Return a static instance of the factory.

Returns
MatcherFactory

◆ string()

Wikimedia\CSS\Grammar\MatcherFactory::string ( )

Matcher for a string.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#strings
Warning
If the string will be used as a URL, use self::urlstring() instead.
Returns
Matcher

◆ time()

Wikimedia\CSS\Grammar\MatcherFactory::time ( )

Matcher for a duration (time) value.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#time
Returns
Matcher

◆ timePercentage()

Wikimedia\CSS\Grammar\MatcherFactory::timePercentage ( )

Matcher for a time-percentage value.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#typedef-time-percentage
Returns
Matcher

◆ url()

Wikimedia\CSS\Grammar\MatcherFactory::url ( $type)

Matcher for a URL.

See also
https://www.w3.org/TR/2019/CR-css-values-3-20190606/#urls
Parameters
string$typeType of resource referenced, e.g. "image" or "audio". Not used here, but might be used by a subclass to validate the URL more strictly.
Returns
Matcher

◆ urlstring()

Wikimedia\CSS\Grammar\MatcherFactory::urlstring ( $type)

Matcher for a string containing a URL.

Parameters
string$typeType of resource referenced, e.g. "image" or "audio". Not used here, but might be used by a subclass to validate the URL more strictly.
Returns
Matcher

◆ zero()

Wikimedia\CSS\Grammar\MatcherFactory::zero ( )

Matches the number 0.

Returns
Matcher

Member Data Documentation

◆ $lengthUnits

Wikimedia\CSS\Grammar\MatcherFactory::$lengthUnits
staticprotected
Initial value:
= [
'em', 'ex', 'ch', 'rem', 'vw', 'vh', 'vmin', 'vmax',
'cm', 'mm', 'Q', 'in', 'pc', 'pt', 'px'
]

The documentation for this class was generated from the following file: