{"record":{"id":"ee16a4de50ea5282","repo":"dotnet/orleans","slug":"input-is-not-in-a-valid-format-encountered-unsupp","errorCode":null,"errorMessage":"Input is not in a valid format: Encountered unsupported escape sequence","messagePattern":"Input is not in a valid format: Encountered unsupported escape sequence","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Azure/Shared/Cosmos/CosmosIdSanitizer.cs","lineNumber":85,"sourceCode":"        }\n\n        if (count == 0)\n        {\n            return input;\n        }\n\n        return string.Create(input.Length - count, input, static (output, input) =>\n        {\n            var i = 0;\n            var isEscaped = false;\n            foreach (var c in input)\n            {\n                if (isEscaped)\n                {\n                    var charId = ReplacementCharacters.IndexOf(c);\n                    if (charId < 0)\n                    {\n                        throw new ArgumentException($\"Input is not in a valid format: Encountered unsupported escape sequence\");\n                    }\n\n                    output[i++] = SanitizedCharacters[charId];\n                    isEscaped = false;\n                }\n                else if (c == EscapeChar)\n                {\n                    isEscaped = true;\n                }\n                else\n                {\n                    output[i++] = c;\n                }\n            }\n        });\n    }\n}","sourceCodeStart":67,"sourceCodeEnd":102,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/src/Azure/Shared/Cosmos/CosmosIdSanitizer.cs#L67-L102","documentation":"Thrown by CosmosIdSanitizer when decoding a previously-sanitized identifier: an escape character is followed by a replacement character that is not in the known ReplacementCharacters set. This means the input is not a string produced by this sanitizer.","triggerScenarios":"Calling the sanitizer's decode path on a hand-authored or externally-produced id that contains the escape char followed by an unexpected character.","commonSituations":"Manually constructing grain ids or Cosmos partition keys that resemble sanitized ids but were never actually sanitized; mixing sanitized and raw ids; a schema change in the sanitizer's escape set across versions.","solutions":["Only pass ids that were produced by the sanitizer's encode path to the decode path.","If the id is user-supplied, run it through the encode (sanitize) direction first.","Avoid constructing ids containing the escape character manually."],"exampleFix":"// before\nvar raw = \"grain|weird\"; // contains sanitizer escape-like sequence\nsanitizer.Decode(raw);\n\n// after\nvar encoded = sanitizer.Encode(userInput); // round-trip safe\nsanitizer.Decode(encoded);","handlingStrategy":"validation","validationCode":"var encoded = sanitizer.Encode(input); // only ever decode encoded output\nvar decoded = sanitizer.Decode(encoded);","typeGuard":"static bool LooksSanitized(string? s) => s is not null && s.IndexOf(EscapeChar) >= 0;","tryCatchPattern":null,"preventionTips":["Round-trip ids through Encode before Decode.","Never hand-author ids containing the sanitizer escape character."],"tags":["cosmos","id-sanitizer","validation","azure"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}