css-sanitizer
Classes to parse and sanitize CSS
|
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 () | |
Factory for predefined Grammar matchers.
::colorFuncs()
. Wikimedia\CSS\Grammar\MatcherFactory::angle | ( | ) |
Matcher for an angle value.
Wikimedia\CSS\Grammar\MatcherFactory::anglePercentage | ( | ) |
Matcher for an angle-percentage value.
Wikimedia\CSS\Grammar\MatcherFactory::bgPosition | ( | ) |
Matcher for a bg-position value.
Wikimedia\CSS\Grammar\MatcherFactory::calc | ( | Matcher | $typeMatcher, |
$type ) |
Add calc() support to a basic type matcher.
Matcher | $typeMatcher | Matcher for the type |
string | $type | Type being matched |
|
protected |
Matcher | $typeMatcher | Matcher for the type |
string | $type | Type being matched |
Wikimedia\CSS\Grammar\MatcherFactory::color | ( | ) |
Matcher for a color value, including a possible custom property reference.
|
protected |
Matchers for color functions.
Wikimedia\CSS\Grammar\MatcherFactory::colorHex | ( | ) |
Wikimedia\CSS\Grammar\MatcherFactory::colorWords | ( | ) |
Wikimedia\CSS\Grammar\MatcherFactory::comma | ( | ) |
Matcher for a comma.
Wikimedia\CSS\Grammar\MatcherFactory::cssANplusB | ( | ) |
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!
Wikimedia\CSS\Grammar\MatcherFactory::cssClass | ( | ) |
A class selector (class)
'.' IDENT
Wikimedia\CSS\Grammar\MatcherFactory::cssCombinator | ( | ) |
A CSS combinator (combinator)
PLUS S* | GREATER S* | TILDE S* | S+
(combinators can be surrounded by whitespace)
Wikimedia\CSS\Grammar\MatcherFactory::cssDeclaration | ( | ?PropertySanitizer | $declarationSanitizer = null | ) |
Matcher for a declaration.
PropertySanitizer | null | $declarationSanitizer | Check declarations against this Sanitizer |
Wikimedia\CSS\Grammar\MatcherFactory::cssID | ( | ) |
An ID selector.
HASH
Wikimedia\CSS\Grammar\MatcherFactory::cssMediaQuery | ( | $strict = true | ) |
Matcher for a CSS media query.
bool | $strict | Only allow defined query types |
Wikimedia\CSS\Grammar\MatcherFactory::cssMediaQueryList | ( | $strict = true | ) |
Matcher for a CSS media query list.
bool | $strict | Only allow defined query types |
Wikimedia\CSS\Grammar\MatcherFactory::cssNamespacePrefix | ( | ) |
A namespace prefix (namespace_prefix)
[ IDENT | '*' ]? '|'
Wikimedia\CSS\Grammar\MatcherFactory::cssNegation | ( | ) |
A negation (negation)
':' not( S* [ type_selector | universal | HASH | class | attrib | pseudo ] S* ')'
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:
Wikimedia\CSS\Grammar\MatcherFactory::cssSelector | ( | ) |
A single selector (selector)
simple_selector_sequence [ combinator simple_selector_sequence ]*
Capturing is set up for the simple_selector_sequence
s (as 'simple') and combinator
.
Wikimedia\CSS\Grammar\MatcherFactory::cssSelectorList | ( | ) |
List of selectors (selectors_group)
selector [ COMMA S* selector ]*
Capturing is set up for the selector
s.
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:
Wikimedia\CSS\Grammar\MatcherFactory::cssSingleEasingFunction | ( | ) |
Matcher for single easing functions from CSS Easing Functions Level 1.
Wikimedia\CSS\Grammar\MatcherFactory::cssSupportsCondition | ( | ?PropertySanitizer | $declarationSanitizer = null, |
$strict = true ) |
Matcher for a "supports-condition".
PropertySanitizer | null | $declarationSanitizer | Check declarations against this Sanitizer |
bool | $strict | Only accept defined syntax. Default true. |
Wikimedia\CSS\Grammar\MatcherFactory::cssTypeSelector | ( | ) |
A type selector, i.e.
a tag name (type_selector)
[ namespace_prefix ] ? element_name
where element_name is
IDENT
Wikimedia\CSS\Grammar\MatcherFactory::cssUniversal | ( | ) |
The universal selector (universal)
[ namespace_prefix ]? '*'
Wikimedia\CSS\Grammar\MatcherFactory::cssWideKeywords | ( | ) |
CSS-wide value keywords.
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.
string[] | $exclude | Additional values to exclude, all-lowercase. |
Wikimedia\CSS\Grammar\MatcherFactory::dimension | ( | ) |
Matcher for a dimension value.
Wikimedia\CSS\Grammar\MatcherFactory::frequency | ( | ) |
Matcher for a frequency value.
Wikimedia\CSS\Grammar\MatcherFactory::frequencyPercentage | ( | ) |
Matcher for a frequency-percentage value.
Wikimedia\CSS\Grammar\MatcherFactory::ident | ( | ) |
Matcher for an arbitrary identifier.
Wikimedia\CSS\Grammar\MatcherFactory::image | ( | ) |
Matcher for an image value.
Wikimedia\CSS\Grammar\MatcherFactory::integer | ( | ) |
Matcher for an integer value.
Wikimedia\CSS\Grammar\MatcherFactory::length | ( | ) |
Matcher for a length value.
Wikimedia\CSS\Grammar\MatcherFactory::lengthPercentage | ( | ) |
Matcher for a length-percentage value.
Wikimedia\CSS\Grammar\MatcherFactory::number | ( | ) |
Matcher for a real number.
Wikimedia\CSS\Grammar\MatcherFactory::numberPercentage | ( | ) |
Matcher for a number-percentage value.
Wikimedia\CSS\Grammar\MatcherFactory::optionalWhitespace | ( | ) |
Matcher for optional whitespace.
Wikimedia\CSS\Grammar\MatcherFactory::percentage | ( | ) |
Matcher for a percentage value.
Wikimedia\CSS\Grammar\MatcherFactory::position | ( | ) |
Matcher for a position value.
|
protected |
Matcher for an angle value, without calc()
|
protected |
Matcher for a frequency value, without calc()
|
protected |
Matcher for an integer value, without calc()
|
protected |
Matcher for a length value, without calc()
Wikimedia\CSS\Grammar\MatcherFactory::rawNumber | ( | ) |
Matcher for a real number, without calc()
Wikimedia\CSS\Grammar\MatcherFactory::rawPercentage | ( | ) |
Matcher for a percentage value, without calc()
|
protected |
Matcher for a duration (time) value, without calc()
Wikimedia\CSS\Grammar\MatcherFactory::resolution | ( | ) |
Matcher for a resolution value.
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.
Wikimedia\CSS\Grammar\MatcherFactory::significantWhitespace | ( | ) |
Matcher for required whitespace.
|
static |
Return a static instance of the factory.
Wikimedia\CSS\Grammar\MatcherFactory::string | ( | ) |
Matcher for a string.
Wikimedia\CSS\Grammar\MatcherFactory::time | ( | ) |
Matcher for a duration (time) value.
Wikimedia\CSS\Grammar\MatcherFactory::timePercentage | ( | ) |
Matcher for a time-percentage value.
Wikimedia\CSS\Grammar\MatcherFactory::url | ( | $type | ) |
Matcher for a URL.
string | $type | Type of resource referenced, e.g. "image" or "audio". Not used here, but might be used by a subclass to validate the URL more strictly. |
Wikimedia\CSS\Grammar\MatcherFactory::urlstring | ( | $type | ) |
Matcher for a string containing a URL.
string | $type | Type of resource referenced, e.g. "image" or "audio". Not used here, but might be used by a subclass to validate the URL more strictly. |
Wikimedia\CSS\Grammar\MatcherFactory::zero | ( | ) |
Matches the number 0.
|
staticprotected |