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

Function _parseConfig

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

Source from the content-addressed store, hash-verified

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

Callers 2

_sanitizeFunction · 0.85
createDOMPurifyFunction · 0.85

Calls 9

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

Tested by

no test coverage detected