(cfg: Config = {})
| 660 | */ |
| 661 | // eslint-disable-next-line complexity |
| 662 | const _parseConfig = function (cfg: Config = {}): void { |
| 663 | /* Shield configuration object from tampering */ |
| 664 | if (!cfg || typeof cfg !== 'object') { |
| 665 | cfg = {}; |
| 666 | } |
| 667 | |
| 668 | /* Shield configuration object from prototype pollution */ |
| 669 | cfg = clone(cfg); |
| 670 | |
| 671 | PARSER_MEDIA_TYPE = |
| 672 | // eslint-disable-next-line unicorn/prefer-includes |
| 673 | SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 |
| 674 | ? DEFAULT_PARSER_MEDIA_TYPE |
| 675 | : cfg.PARSER_MEDIA_TYPE; |
| 676 | |
| 677 | // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is. |
| 678 | transformCaseFunc = |
| 679 | PARSER_MEDIA_TYPE === 'application/xhtml+xml' |
| 680 | ? stringToString |
| 681 | : stringToLowerCase; |
| 682 | |
| 683 | /* Set configuration parameters */ |
| 684 | ALLOWED_TAGS = _resolveSetOption( |
| 685 | cfg, |
| 686 | 'ALLOWED_TAGS', |
| 687 | DEFAULT_ALLOWED_TAGS, |
| 688 | { transform: transformCaseFunc } |
| 689 | ); |
| 690 | ALLOWED_ATTR = _resolveSetOption( |
| 691 | cfg, |
| 692 | 'ALLOWED_ATTR', |
| 693 | DEFAULT_ALLOWED_ATTR, |
| 694 | { transform: transformCaseFunc } |
| 695 | ); |
| 696 | ALLOWED_NAMESPACES = _resolveSetOption( |
| 697 | cfg, |
| 698 | 'ALLOWED_NAMESPACES', |
| 699 | DEFAULT_ALLOWED_NAMESPACES, |
| 700 | { transform: stringToString } |
| 701 | ); |
| 702 | URI_SAFE_ATTRIBUTES = _resolveSetOption( |
| 703 | cfg, |
| 704 | 'ADD_URI_SAFE_ATTR', |
| 705 | DEFAULT_URI_SAFE_ATTRIBUTES, |
| 706 | { transform: transformCaseFunc, base: DEFAULT_URI_SAFE_ATTRIBUTES } |
| 707 | ); |
| 708 | DATA_URI_TAGS = _resolveSetOption( |
| 709 | cfg, |
| 710 | 'ADD_DATA_URI_TAGS', |
| 711 | DEFAULT_DATA_URI_TAGS, |
| 712 | { transform: transformCaseFunc, base: DEFAULT_DATA_URI_TAGS } |
| 713 | ); |
| 714 | FORBID_CONTENTS = _resolveSetOption( |
| 715 | cfg, |
| 716 | 'FORBID_CONTENTS', |
| 717 | DEFAULT_FORBID_CONTENTS, |
| 718 | { transform: transformCaseFunc } |
| 719 | ); |
no test coverage detected