Skip to content

Latest commit

 

History

History
751 lines (273 loc) · 6.33 KB

SVGSanitizer.md

File metadata and controls

751 lines (273 loc) · 6.33 KB

SVGSanitizer

Class SVGSanitizer

simplified/compact version of svg-sanitizer - https://github.com/darylldoyle/svg-sanitizer by Daryll Doyle

  • Full name: \SVGSanitizer

Constants

Constant Visibility Type Value
SCRIPT_REGEX public '/(?:\w+script

Properties

xmlDocument

protected \DOMDocument $xmlDocument

allowedTags

protected array $allowedTags

allowedAttrs

protected array $allowedAttrs

xmlLoaderValue

protected $xmlLoaderValue

minifyXML

protected bool $minifyXML

removeRemoteReferences

protected bool $removeRemoteReferences

removeXMLTag

protected bool $removeXMLTag

xmlOptions

protected int $xmlOptions

Methods

clean

SVGSanitizer::clean('<svg ...>')

public static clean(mixed $svgText): mixed
  • This method is static.

Parameters:

Parameter Type Description
$svgText mixed

__construct

public __construct(): mixed

resetInternal

Set up the DOMDocument

protected resetInternal(): mixed

setXMLOptions

Set XML options to use when saving XML See: DOMDocument::saveXML

public setXMLOptions(int $xmlOptions): mixed

Parameters:

Parameter Type Description
$xmlOptions int

getXMLOptions

Get XML options to use when saving XML See: DOMDocument::saveXML

public getXMLOptions(): int

getAllowedTags

Get the array of allowed tags

public getAllowedTags(): array

setAllowedTags

Set custom allowed tags

public setAllowedTags(array $allowedTags): mixed

Parameters:

Parameter Type Description
$allowedTags array

getAllowedAttrs

Get the array of allowed attributes

public getAllowedAttrs(): array

setAllowedAttrs

Set custom allowed attributes

public setAllowedAttrs(array $allowedAttrs): mixed

Parameters:

Parameter Type Description
$allowedAttrs array

removeRemoteReferences

Should we remove references to remote files?

public removeRemoteReferences(bool $removeRemoteRefs = false): mixed

Parameters:

Parameter Type Description
$removeRemoteRefs bool

sanitize

Sanitize the passed string

public sanitize(string $dirty): string

Parameters:

Parameter Type Description
$dirty string

setUpBefore

Set up libXML before we start

protected setUpBefore(): mixed

resetAfter

Reset the class after use

protected resetAfter(): mixed

removeDoctype

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

startClean

Start the cleaning with tags, then we move onto attributes and hrefs later

protected startClean(\DOMNodeList $elements): mixed

Parameters:

Parameter Type Description
$elements \DOMNodeList

cleanAttributesOnWhitelist

Only allow attributes that are on the whitelist

protected cleanAttributesOnWhitelist(\DOMElement $element): mixed

Parameters:

Parameter Type Description
$element \DOMElement

cleanXlinkHrefs

Clean the xlink:hrefs of script and data embeds

protected cleanXlinkHrefs(\DOMElement $element): mixed

Parameters:

Parameter Type Description
$element \DOMElement

cleanHrefs

Clean the hrefs of script and data embeds

protected cleanHrefs(\DOMElement $element): mixed

Parameters:

Parameter Type Description
$element \DOMElement

removeNonPrintableCharacters

Removes non-printable ASCII characters from string & trims it

protected removeNonPrintableCharacters(string $value): bool

Parameters:

Parameter Type Description
$value string

hasRemoteReference

Does this attribute value have a remote reference?

protected hasRemoteReference( $value): bool

Parameters:

Parameter Type Description
$value ****

minify

Should we minify the output?

public minify(bool $shouldMinify = false): mixed

Parameters:

Parameter Type Description
$shouldMinify bool

removeXMLTag

Should we remove the XML tag in the header?

public removeXMLTag(bool $removeXMLTag = false): mixed

Parameters:

Parameter Type Description
$removeXMLTag bool

isAriaAttribute

Check to see if an attribute is an aria attribute or not

protected isAriaAttribute( $attributeName): bool

Parameters:

Parameter Type Description
$attributeName ****

isDataAttribute

Check to see if an attribute is an data attribute or not

protected isDataAttribute( $attributeName): bool

Parameters:

Parameter Type Description
$attributeName ****

isUseTagDirty

Make sure our use tag is only referencing internal resources

protected isUseTagDirty(\DOMElement $element): bool

Parameters:

Parameter Type Description
$element \DOMElement