{"record":{"id":"be72ef3cb09df401","repo":"karatelabs/karate","slug":"the-normalization-form-should-be-one-of-nfc-nfd-nfkc-nfkd","errorCode":null,"errorMessage":"The normalization form should be one of NFC, NFD, NFKC, NFKD","messagePattern":"The normalization form should be one of NFC, NFD, NFKC, NFKD","errorType":"exception","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JsStringPrototype.java","lineNumber":703,"sourceCode":"        int index = argInt(args, 0, 0);\n        if (index < 0) {\n            index = s.length() + index;\n        }\n        if (index < 0 || index >= s.length()) {\n            return Terms.UNDEFINED;\n        }\n        return String.valueOf(s.charAt(index));\n    }\n\n    private Object normalize(Context context, Object[] args) {\n        String s = thisString(context, \"normalize\");\n        String form = (args.length > 0 && args[0] != Terms.UNDEFINED) ? argString(args, 0, context) : \"NFC\";\n        return switch (form) {\n            case \"NFC\" -> java.text.Normalizer.normalize(s, java.text.Normalizer.Form.NFC);\n            case \"NFD\" -> java.text.Normalizer.normalize(s, java.text.Normalizer.Form.NFD);\n            case \"NFKC\" -> java.text.Normalizer.normalize(s, java.text.Normalizer.Form.NFKC);\n            case \"NFKD\" -> java.text.Normalizer.normalize(s, java.text.Normalizer.Form.NFKD);\n            default -> throw JsErrorException.rangeError(\"The normalization form should be one of NFC, NFD, NFKC, NFKD\");\n        };\n    }\n\n    private Object localeCompare(Context context, Object[] args) {\n        String s = thisString(context, \"localeCompare\");\n        String other = argString(args, 0, context);\n        return Integer.signum(s.compareToIgnoreCase(other));\n    }\n\n}\n","sourceCodeStart":685,"sourceCodeEnd":714,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JsStringPrototype.java#L685-L714","documentation":"This RangeError is thrown by String.prototype.normalize when the argument is not one of the four accepted normalization forms: NFC, NFD, NFKC, NFKD. Any other string (including lowercase variants like 'nfc', or unrelated values) fails the switch and raises the error. Omitting the argument or passing undefined defaults to NFC and is safe.","triggerScenarios":"Calling 'str'.normalize('Nfc') (case-sensitive check), 'str'.normalize('UTF8'), or 'str'.normalize(customForm) where the form string comes from configuration or user input.","commonSituations":"Form names read from config files or CLI options with inconsistent casing; confusion with encoding names like UTF-8; uppercasing forgotten when normalizing user-supplied form names.","solutions":["Pass one of the exact forms: 'NFC', 'NFD', 'NFKC', or 'NFKD'","Normalize case before calling: s.normalize(form.toUpperCase())","Whitelist-validate: if (['NFC','NFD','NFKC','NFKD'].includes(form)) before invoking"],"exampleFix":"// before\ns.normalize(form); // RangeError when form = 'nfc'\n// after\ns.normalize(form.toUpperCase()); // or validate against the 4 allowed forms first","handlingStrategy":"validation","validationCode":"const VALID_FORMS = ['NFC','NFD','NFKC','NFKD']; const canNormalize = (f) => f === undefined || VALID_FORMS.includes(f);","typeGuard":"const isNormalizationForm = (f) => typeof f === 'string' && ['NFC','NFD','NFKC','NFKD'].includes(f);","tryCatchPattern":"try { return s.normalize(form); } catch (e) { if (e.name === 'RangeError') return s.normalize(); /* NFC default */ throw e; }","preventionTips":["Uppercase and validate config-driven form names before calling normalize","Do not confuse normalization forms with encodings like UTF-8","Omit the argument when NFC (the default) is desired"],"tags":["javascript","string","unicode","range-error"],"backgroundTag":"invalid-enum-value","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}