Skip to content

FileExtension/FullFileExtension throw ArgumentException for any path with a dot in a directory name ("./notes.txt", "/home/u/.config/a.json") #287

Description

@matt-edmondson

What's wrong

In Semantics.Paths/SemanticFilePath.cs:

  • FileExtension (around line 14) searches the entire path with LastIndexOf('.').
  • FullFileExtension (around line 53) does the same with IndexOf('.').

Neither limits the search to the file-name segment. When a directory component contains a dot, the substring handed to FileExtension.Create includes a directory separator. IsFileExtensionAttribute rejects that, so the property getter throws.

Failure scenarios (Linux, reproduced)

Expression Result
AbsoluteFilePath("/home/user/.config/settings.json").FullFileExtension ArgumentException: Cannot convert ".config/settings.json" to FileExtension
RelativeFilePath("../data/archive.tar.gz").FullFileExtension throws for "../data/archive.tar.gz"
FilePath("./notes.txt").FullFileExtension throws for "./notes.txt"
AbsoluteFilePath("/opt/app.v2/README").FileExtension throws for ".v2/README"; it should return an empty extension

Paths with ./, ../, dot-directories such as .config, .git and .vscode, or versioned folder names are everyday input. For all of them, a simple property read throws. The existing tests use bare file names only (for example "test.tar.gz"), so the bug goes unnoticed.

Suggested fix

Work on the file-name segment only. Slice after the last / or \ (or use Path.GetFileName) before searching for dots. For FullFileExtension, also skip a leading dot in the file name, so .bashrc is treated as a name with no extension rather than an extension.

Acceptance criteria

  • "./notes.txt" → FileExtension == ".txt" and FullFileExtension == ".txt".
  • "../data/archive.tar.gz" → FileExtension == ".gz" and FullFileExtension == ".tar.gz".
  • "/opt/app.v2/README" → both are empty.
  • "/home/user/.bashrc" → both are empty, per the chosen dotfile rule, which should be documented.
  • The tests cover both the netstandard2.0 branch and the span branch.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    readyFully specified; implement as written

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions