{"record":{"id":"e5980f5d9c82f0d2","repo":"iOfficeAI/OfficeCLI","slug":"invalid-path-path-leading-is-not-allowed","errorCode":null,"errorMessage":"Invalid path '{path}': leading '//' is not allowed.","messagePattern":"Invalid path '(.+?)': leading '//' is not allowed\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"warning","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Helpers.Sheet.cs","lineNumber":109,"sourceCode":"    /// </summary>\n    // Excel-quoted sheet name: 'My Data (2024)'!A1 — strip one pair of single\n    // quotes and un-double embedded quotes ('It''s'!A1 → It's). Excel REQUIRES\n    // the quoted form for names with spaces/punctuation, so refs pasted from\n    // formulas arrive quoted. Unquoted names pass through unchanged.\n    internal static string UnquoteSheetName(string s)\n        => s.Length >= 2 && s[0] == '\\'' && s[^1] == '\\''\n            ? s[1..^1].Replace(\"''\", \"'\")\n            : s;\n\n    internal string NormalizeExcelPath(string path)\n    {\n        // Reject malformed segment separators that previously slipped past\n        // the regex matchers and exposed raw OOXML local names. DOCX already\n        // rejects these; bring XLSX up to parity.\n        if (path.Length > 1 && path != \"/\" && path.EndsWith(\"/\"))\n            throw new ArgumentException($\"Invalid path '{path}': trailing '/' is not allowed.\");\n        if (path.StartsWith(\"//\"))\n            throw new ArgumentException($\"Invalid path '{path}': leading '//' is not allowed.\");\n        if (path.Contains(\"//\"))\n            throw new ArgumentException($\"Invalid path '{path}': empty path segment ('//') is not allowed.\");\n        // Handle \"/Sheet1!A1\" — strip leading '/' when '!' is present so native\n        // notation is parsed correctly. EXCEPT when the first slash segment\n        // names an existing sheet: '!' is legal inside a sheet NAME (Excel\n        // forbids only : \\ / ? * [ ]), and reinterpreting \"/Q1!Results\" as\n        // bang notation made such a sheet permanently unaddressable.\n        if (path.StartsWith('/') && path.Contains('!'))\n        {\n            var seg0 = path[1..];\n            var seg0Slash = seg0.IndexOf('/');\n            var first = seg0Slash < 0 ? seg0 : seg0[..seg0Slash];\n            if (!GetWorksheets().Any(w => w.Name.Equals(first, StringComparison.OrdinalIgnoreCase)))\n                path = path[1..];\n        }\n        if (path.Equals(\"/workbook\", StringComparison.OrdinalIgnoreCase)) return \"/\";\n        if (path.StartsWith('/')) return path;\n        // Excel-quoted sheet ref: 'My Data'!A1 — the '!' separator is the one","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.Sheet.cs#L91-L127","documentation":"Thrown by NormalizeExcelPath when the path starts with '//'. A leading double slash implies an empty first segment; DOCX already rejected this and XLSX was brought to parity so malformed separators do not expose raw OOXML local names.","triggerScenarios":"Calling a path-based Excel API with '//Sheet1/A1', '///root', or any path beginning with two or more slashes. Common when concatenating '/' + path where path already starts with '/'.","commonSituations":"Joining a base path that ends in '/' with a child that begins with '/'; copying URL-handling code into path handling; treating '/' like an empty host prefix.","solutions":["Ensure exactly one leading slash: if both segments have one, drop one before joining.","Use string.TrimStart('/') once then prepend a single '/'.","Validate the joined path with the NormalizePath helper shown for error 704."],"exampleFix":"// before\nstring path = baseDir.EndsWith('/') ? baseDir + child : baseDir + \"/\" + child;\n// when baseDir='/' and child='/Sheet1' → '//Sheet1'\n// after\nstring joined = string.Join('/', new[] { baseDir.TrimEnd('/'), child.TrimStart('/') });\nif (!joined.StartsWith('/')) joined = \"/\" + joined;","handlingStrategy":"validation","validationCode":"static string EnsureSingleLeadingSlash(string p)\n    => p.StartsWith(\"//\") ? \"/\" + p.TrimStart('/') : p;","typeGuard":"null","tryCatchPattern":"try { NormalizeExcelPath(path); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"leading '//'\"))\n{ path = \"/\" + path.TrimStart('/'); }","preventionTips":["Never join two segments that both carry a leading or trailing '/'.","Sanitize at the boundary before passing to path APIs.","Reject paths with empty first segments at parse time."],"tags":["paths","excel","input-validation","normalization"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}