zk/src/main/resources/web/js/zk/ext/purify.js

Summary

Maintainability
F
1 wk
Test Coverage

Function createDOMPurify has 714 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  function createDOMPurify() {
    let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();

    const DOMPurify = root => createDOMPurify(root);
    /**
Severity: Major
Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 3 days to fix

    File purify.js has 896 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /*! @license DOMPurify 3.0.6 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.6/LICENSE */
    
    (function (global, factory) {
      typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
      typeof define === 'function' && define.amd ? define(factory) :
    Severity: Major
    Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 2 days to fix

      Function _parseConfig has 135 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          const _parseConfig = function _parseConfig() {
            let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      
            if (CONFIG && CONFIG === cfg) {
              return;
      Severity: Major
      Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 5 hrs to fix

        Function sanitize has 96 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            DOMPurify.sanitize = function (dirty) {
              let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
              let body = null;
              let importedNode = null;
              let currentNode = null;
        Severity: Major
        Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 3 hrs to fix

          Consider simplifying this complex logical expression.
          Open

                  if ( // First condition does a very basic check if a) it's basically a valid custom element tagname AND
                  // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
                  // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
                  _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) || // Alternative, second condition checks if it's an `is`-attribute, AND
                  // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
          Severity: Critical
          Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 3 hrs to fix

            Function _sanitizeAttributes has 79 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
                  /* Execute a hook if present */
                  _executeHook('beforeSanitizeAttributes', currentNode, null);
            
                  const {
            Severity: Major
            Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 3 hrs to fix

              Function _sanitizeElements has 59 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  const _sanitizeElements = function _sanitizeElements(currentNode) {
                    let content = null;
                    /* Execute a hook if present */
              
                    _executeHook('beforeSanitizeElements', currentNode, null);
              Severity: Major
              Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 2 hrs to fix

                Function _checkValidNamespace has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    const _checkValidNamespace = function _checkValidNamespace(element) {
                      let parent = getParentNode(element); // In JSDOM, if we're inside shadow DOM, then parentNode
                      // can be null. We just simulate parent in this case.
                
                      if (!parent || !parent.tagName) {
                Severity: Minor
                Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 1 hr to fix

                  Function _initDocument has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      const _initDocument = function _initDocument(dirty) {
                        /* Create a HTML document */
                        let doc = null;
                        let leadingWhitespace = null;
                  
                  
                  Severity: Minor
                  Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 1 hr to fix

                    Consider simplifying this complex logical expression.
                    Open

                          } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {
                            return false;
                          } else ;
                    Severity: Major
                    Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 40 mins to fix

                      Consider simplifying this complex logical expression.
                      Open

                            if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
                              serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
                            }
                      Severity: Major
                      Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 40 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                return true;
                        Severity: Major
                        Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                    return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
                          Severity: Major
                          Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                    return true;
                            Severity: Major
                            Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                    return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
                              Severity: Major
                              Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                          return false;
                                Severity: Major
                                Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                            return false;
                                  Severity: Major
                                  Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                            return Boolean(ALL_MATHML_TAGS[tagName]);
                                    Severity: Major
                                    Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                            return false;
                                      Severity: Major
                                      Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                              return false;
                                        Severity: Major
                                        Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                    return tagName === 'math';
                                          Severity: Major
                                          Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 30 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                                    return true;
                                            Severity: Major
                                            Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 30 mins to fix

                                              Avoid too many return statements within this function.
                                              Open

                                                      return returnNode;
                                              Severity: Major
                                              Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 30 mins to fix

                                                Avoid too many return statements within this function.
                                                Open

                                                        return true;
                                                Severity: Major
                                                Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 30 mins to fix

                                                  Avoid too many return statements within this function.
                                                  Open

                                                          return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
                                                  Severity: Major
                                                  Found in zk/src/main/resources/web/js/zk/ext/purify.js - About 30 mins to fix

                                                    Similar blocks of code found in 3 locations. Consider refactoring.
                                                    Open

                                                            _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) || // Alternative, second condition checks if it's an `is`-attribute, AND
                                                    Severity: Minor
                                                    Found in zk/src/main/resources/web/js/zk/ext/purify.js and 2 other locations - About 35 mins to fix
                                                    zk/src/main/resources/web/js/zk/ext/purify.js on lines 1171..1171
                                                    zk/src/main/resources/web/js/zk/ext/purify.js on lines 1173..1173

                                                    Duplicated Code

                                                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                    Tuning

                                                    This issue has a mass of 47.

                                                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                    Refactorings

                                                    Further Reading

                                                    Similar blocks of code found in 3 locations. Consider refactoring.
                                                    Open

                                                            lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {
                                                    Severity: Minor
                                                    Found in zk/src/main/resources/web/js/zk/ext/purify.js and 2 other locations - About 35 mins to fix
                                                    zk/src/main/resources/web/js/zk/ext/purify.js on lines 1171..1171
                                                    zk/src/main/resources/web/js/zk/ext/purify.js on lines 1171..1171

                                                    Duplicated Code

                                                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                    Tuning

                                                    This issue has a mass of 47.

                                                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                    Refactorings

                                                    Further Reading

                                                    Similar blocks of code found in 2 locations. Consider refactoring.
                                                    Open

                                                          if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
                                                            CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
                                                          }
                                                    Severity: Minor
                                                    Found in zk/src/main/resources/web/js/zk/ext/purify.js and 1 other location - About 35 mins to fix
                                                    zk/src/main/resources/web/js/zk/ext/purify.js on lines 617..619

                                                    Duplicated Code

                                                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                    Tuning

                                                    This issue has a mass of 46.

                                                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                    Refactorings

                                                    Further Reading

                                                    Similar blocks of code found in 2 locations. Consider refactoring.
                                                    Open

                                                          if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
                                                            CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
                                                          }
                                                    Severity: Minor
                                                    Found in zk/src/main/resources/web/js/zk/ext/purify.js and 1 other location - About 35 mins to fix
                                                    zk/src/main/resources/web/js/zk/ext/purify.js on lines 621..623

                                                    Duplicated Code

                                                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                    Tuning

                                                    This issue has a mass of 46.

                                                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                    Refactorings

                                                    Further Reading

                                                    There are no issues that match your filters.

                                                    Category
                                                    Status