(cfg: Config = {})
| 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, |
no test coverage detected