Class SVGSanitizer
simplified/compact version of svg-sanitizer - https://github.com/darylldoyle/svg-sanitizer by Daryll Doyle
- Full name:
\SVGSanitizer
Constant | Visibility | Type | Value |
---|---|---|---|
SCRIPT_REGEX |
public | '/(?:\w+script |
protected \DOMDocument $xmlDocument
protected array $allowedTags
protected array $allowedAttrs
protected $xmlLoaderValue
protected bool $minifyXML
protected bool $removeRemoteReferences
protected bool $removeXMLTag
protected int $xmlOptions
SVGSanitizer::clean('<svg ...>')
public static clean(mixed $svgText): mixed
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$svgText |
mixed |
public __construct(): mixed
Set up the DOMDocument
protected resetInternal(): mixed
Set XML options to use when saving XML See: DOMDocument::saveXML
public setXMLOptions(int $xmlOptions): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$xmlOptions |
int |
Get XML options to use when saving XML See: DOMDocument::saveXML
public getXMLOptions(): int
Get the array of allowed tags
public getAllowedTags(): array
Set custom allowed tags
public setAllowedTags(array $allowedTags): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$allowedTags |
array |
Get the array of allowed attributes
public getAllowedAttrs(): array
Set custom allowed attributes
public setAllowedAttrs(array $allowedAttrs): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$allowedAttrs |
array |
Should we remove references to remote files?
public removeRemoteReferences(bool $removeRemoteRefs = false): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$removeRemoteRefs |
bool |
Sanitize the passed string
public sanitize(string $dirty): string
Parameters:
Parameter | Type | Description |
---|---|---|
$dirty |
string |
Set up libXML before we start
protected setUpBefore(): mixed
Reset the class after use
protected resetAfter(): mixed
Remove the XML Doctype It may be caught later on output but that seems to be buggy, so we need to make sure it's gone
protected removeDoctype(): mixed
Start the cleaning with tags, then we move onto attributes and hrefs later
protected startClean(\DOMNodeList $elements): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$elements |
\DOMNodeList |
Only allow attributes that are on the whitelist
protected cleanAttributesOnWhitelist(\DOMElement $element): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$element |
\DOMElement |
Clean the xlink:hrefs of script and data embeds
protected cleanXlinkHrefs(\DOMElement $element): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$element |
\DOMElement |
Clean the hrefs of script and data embeds
protected cleanHrefs(\DOMElement $element): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$element |
\DOMElement |
Removes non-printable ASCII characters from string & trims it
protected removeNonPrintableCharacters(string $value): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$value |
string |
Does this attribute value have a remote reference?
protected hasRemoteReference( $value): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$value |
**** |
Should we minify the output?
public minify(bool $shouldMinify = false): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$shouldMinify |
bool |
Should we remove the XML tag in the header?
public removeXMLTag(bool $removeXMLTag = false): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$removeXMLTag |
bool |
Check to see if an attribute is an aria attribute or not
protected isAriaAttribute( $attributeName): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$attributeName |
**** |
Check to see if an attribute is an data attribute or not
protected isDataAttribute( $attributeName): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$attributeName |
**** |
Make sure our use tag is only referencing internal resources
protected isUseTagDirty(\DOMElement $element): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$element |
\DOMElement |