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

Function _parseConfig

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

Source from the content-addressed store, hash-verified

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