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

Function _parseConfig

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

Source from the content-addressed store, hash-verified

633 */
634 // eslint-disable-next-line complexity
635 const _parseConfig = function (cfg: Config = {}): void {
636 if (CONFIG && CONFIG === cfg) {
637 return;
638 }
639
640 /* Shield configuration object from tampering */
641 if (!cfg || typeof cfg !== 'object') {
642 cfg = {};
643 }
644
645 /* Shield configuration object from prototype pollution */
646 cfg = clone(cfg);
647
648 PARSER_MEDIA_TYPE =
649 // eslint-disable-next-line unicorn/prefer-includes
650 SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1
651 ? DEFAULT_PARSER_MEDIA_TYPE
652 : cfg.PARSER_MEDIA_TYPE;
653
654 // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
655 transformCaseFunc =
656 PARSER_MEDIA_TYPE === 'application/xhtml+xml'
657 ? stringToString
658 : stringToLowerCase;
659
660 /* Set configuration parameters */
661 ALLOWED_TAGS = _resolveSetOption(
662 cfg,
663 'ALLOWED_TAGS',
664 DEFAULT_ALLOWED_TAGS,
665 { transform: transformCaseFunc }
666 );
667 ALLOWED_ATTR = _resolveSetOption(
668 cfg,
669 'ALLOWED_ATTR',
670 DEFAULT_ALLOWED_ATTR,
671 { transform: transformCaseFunc }
672 );
673 ALLOWED_NAMESPACES = _resolveSetOption(
674 cfg,
675 'ALLOWED_NAMESPACES',
676 DEFAULT_ALLOWED_NAMESPACES,
677 { transform: stringToString }
678 );
679 URI_SAFE_ATTRIBUTES = _resolveSetOption(
680 cfg,
681 'ADD_URI_SAFE_ATTR',
682 DEFAULT_URI_SAFE_ATTRIBUTES,
683 { transform: transformCaseFunc, base: DEFAULT_URI_SAFE_ATTRIBUTES }
684 );
685 DATA_URI_TAGS = _resolveSetOption(
686 cfg,
687 'ADD_DATA_URI_TAGS',
688 DEFAULT_DATA_URI_TAGS,
689 { transform: transformCaseFunc, base: DEFAULT_DATA_URI_TAGS }
690 );
691 FORBID_CONTENTS = _resolveSetOption(
692 cfg,

Callers 1

createDOMPurifyFunction · 0.85

Calls 7

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

Tested by

no test coverage detected