MCPcopy Create free account
hub / github.com/cure53/DOMPurify / _parseConfig

Function _parseConfig

src/purify.ts:720–1028  ·  view source on GitHub ↗
(cfg: Config = {})

Source from the content-addressed store, hash-verified

718 */
719 // eslint-disable-next-line complexity
720 const _parseConfig = function (cfg: Config = {}): void {
721 if (CONFIG && CONFIG === cfg) {
722 return;
723 }
724
725 /* Shield configuration object from tampering */
726 if (!cfg || typeof cfg !== 'object') {
727 cfg = {};
728 }
729
730 /* Shield configuration object from prototype pollution */
731 cfg = clone(cfg);
732
733 PARSER_MEDIA_TYPE =
734 // eslint-disable-next-line unicorn/prefer-includes
735 SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1
736 ? DEFAULT_PARSER_MEDIA_TYPE
737 : cfg.PARSER_MEDIA_TYPE;
738
739 // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
740 transformCaseFunc =
741 PARSER_MEDIA_TYPE === 'application/xhtml+xml'
742 ? stringToString
743 : stringToLowerCase;
744
745 /* Set configuration parameters */
746 ALLOWED_TAGS = _resolveSetOption(
747 cfg,
748 'ALLOWED_TAGS',
749 DEFAULT_ALLOWED_TAGS,
750 { transform: transformCaseFunc }
751 );
752 ALLOWED_ATTR = _resolveSetOption(
753 cfg,
754 'ALLOWED_ATTR',
755 DEFAULT_ALLOWED_ATTR,
756 { transform: transformCaseFunc }
757 );
758 ALLOWED_NAMESPACES = _resolveSetOption(
759 cfg,
760 'ALLOWED_NAMESPACES',
761 DEFAULT_ALLOWED_NAMESPACES,
762 { transform: stringToString }
763 );
764 URI_SAFE_ATTRIBUTES = _resolveSetOption(
765 cfg,
766 'ADD_URI_SAFE_ATTR',
767 DEFAULT_URI_SAFE_ATTRIBUTES,
768 { transform: transformCaseFunc, base: DEFAULT_URI_SAFE_ATTRIBUTES }
769 );
770 DATA_URI_TAGS = _resolveSetOption(
771 cfg,
772 'ADD_DATA_URI_TAGS',
773 DEFAULT_DATA_URI_TAGS,
774 { transform: transformCaseFunc, base: DEFAULT_DATA_URI_TAGS }
775 );
776 FORBID_CONTENTS = _resolveSetOption(
777 cfg,

Callers 1

createDOMPurifyFunction · 0.85

Calls 8

cloneFunction · 0.85
_resolveSetOptionFunction · 0.85
isRegexFunction · 0.85
_resolveObjectOptionFunction · 0.85
addToSetFunction · 0.85
isRegexOrFunctionFunction · 0.85
_createTrustedHTMLFunction · 0.85

Tested by

no test coverage detected