iOfficeAI/OfficeCLI · warning · ArgumentException
Invalid path '{path}': leading '//' is not allowed.
Error message
Invalid path '{path}': leading '//' is not allowed. What it means
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.
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Helpers.Sheet.cs:109
/// </summary>
// Excel-quoted sheet name: 'My Data (2024)'!A1 — strip one pair of single
// quotes and un-double embedded quotes ('It''s'!A1 → It's). Excel REQUIRES
// the quoted form for names with spaces/punctuation, so refs pasted from
// formulas arrive quoted. Unquoted names pass through unchanged.
internal static string UnquoteSheetName(string s)
=> s.Length >= 2 && s[0] == '\'' && s[^1] == '\''
? s[1..^1].Replace("''", "'")
: s;
internal string NormalizeExcelPath(string path)
{
// Reject malformed segment separators that previously slipped past
// the regex matchers and exposed raw OOXML local names. DOCX already
// rejects these; bring XLSX up to parity.
if (path.Length > 1 && path != "/" && path.EndsWith("/"))
throw new ArgumentException($"Invalid path '{path}': trailing '/' is not allowed.");
if (path.StartsWith("//"))
throw new ArgumentException($"Invalid path '{path}': leading '//' is not allowed.");
if (path.Contains("//"))
throw new ArgumentException($"Invalid path '{path}': empty path segment ('//') is not allowed.");
// Handle "/Sheet1!A1" — strip leading '/' when '!' is present so native
// notation is parsed correctly. EXCEPT when the first slash segment
// names an existing sheet: '!' is legal inside a sheet NAME (Excel
// forbids only : \ / ? * [ ]), and reinterpreting "/Q1!Results" as
// bang notation made such a sheet permanently unaddressable.
if (path.StartsWith('/') && path.Contains('!'))
{
var seg0 = path[1..];
var seg0Slash = seg0.IndexOf('/');
var first = seg0Slash < 0 ? seg0 : seg0[..seg0Slash];
if (!GetWorksheets().Any(w => w.Name.Equals(first, StringComparison.OrdinalIgnoreCase)))
path = path[1..];
}
if (path.Equals("/workbook", StringComparison.OrdinalIgnoreCase)) return "/";
if (path.StartsWith('/')) return path;
// Excel-quoted sheet ref: 'My Data'!A1 — the '!' separator is the oneView on GitHub (pinned to 1ced45e900)
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.
Example fix
// before
string path = baseDir.EndsWith('/') ? baseDir + child : baseDir + "/" + child;
// when baseDir='/' and child='/Sheet1' → '//Sheet1'
// after
string joined = string.Join('/', new[] { baseDir.TrimEnd('/'), child.TrimStart('/') });
if (!joined.StartsWith('/')) joined = "/" + joined; Defensive patterns
Strategy: validation
Validate before calling
static string EnsureSingleLeadingSlash(string p)
=> p.StartsWith("//") ? "/" + p.TrimStart('/') : p; Type guard
null
Try / catch
try { NormalizeExcelPath(path); }
catch (ArgumentException ex) when (ex.Message.Contains("leading '//'"))
{ path = "/" + path.TrimStart('/'); } Prevention
- 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.
When it happens
Trigger: 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 '/'.
Common situations: 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.
Related errors
- Invalid path '{path}': trailing '/' is not allowed.
- Invalid path '{path}': empty path segment ('//') is not allo
- Invalid '{propertyName}' value '{value}'. Expected a non-neg
- Invalid color value: '{value}'. Expected 6-digit hex RGB (e.
- Invalid source range: {sourceRef}
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/e5980f5d9c82f0d2.
Report an issue: GitHub.