Skip to content

[repo-assist] Fix createRelativePath mangling paths with special characters (#, %, &) - #4359

Merged
dsyme merged 1 commit into
masterfrom
repo-assist/fix-createrelativepath-special-chars-e30c51c3ea57b1ec
Aug 26, 2026
Merged

dsyme merged 1 commit into
masterfrom
repo-assist/fix-createrelativepath-special-chars-e30c51c3ea57b1ec

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This PR was authored by Repo Assist, an automated AI assistant, as part of routine testing-improvement work on this repository.

Root cause

createRelativePath (in src/Paket.Core/Common/Utils.fs) builds a relative path using Uri.MakeRelativeUri, which percent-encodes reserved/special characters in the resulting URI string (spaces, #, %, &, etc.). The existing code only reversed the space encoding (Replace("%20", " ")), so any file or directory name containing other special characters — most notably # — would come back with the escaped sequence baked into the path string (e.g. some#file → some%23file).

This function is used throughout project-file and template-file writers (ProjectFile.fs, InstallProcess.fs, NugetConvert.fs, LocalFile.fs, DependenciesFileParser.fs), so any file/folder name with such characters could end up with a mangled path written into a .csproj/.fsproj, paket.local, etc.

Fix

Replaced the single %20-specific replace with Uri.UnescapeDataString(...), which unescapes all percent-encoded characters generically, not just spaces.

Trade-offs

This is a minimal, surgical change to one small function. Uri.UnescapeDataString is part of the base class library and behaves as a strict superset of the previous %20-only replace, so all previously passing behavior (including the existing "handle spaces" test) is preserved.

Tests

Added three new tests to tests/Paket.Tests/UtilsSpecs.fs covering #, &, and % characters in relative paths, alongside the existing space-handling test.

Test Status

  • dotnet build src/Paket.Core/Paket.Core.fsproj -f netstandard2.0 — succeeded, 0 errors (11 pre-existing warnings unrelated to this change).
  • dotnet test tests/Paket.Tests/Paket.Tests.fsproj -f net9 --filter "FullyQualifiedName~UtilsSpecs.createRelativePath" — 4/4 passed (1 existing + 3 new).
  • dotnet test tests/Paket.Tests/Paket.Tests.fsproj -f net9 --filter "FullyQualifiedName~ParserSpecs|FullyQualifiedName~SaveSpecs" — 172/172 passed, no regressions.
  • Full UtilsSpecs run showed 4 pre-existing, unrelated failures (proxy env-var parsing tests that also fail on main without this change) — not caused by this PR.

Generated by 🌈 Repo Assist, see workflow run. Learn more.
Comment /repo-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@ae8d551f07c7ed7619f8c58c7bb4c3ac89395d38

createRelativePath used Uri.MakeRelativeUri, which percent-encodes
reserved characters such as #, %, and &. The previous code only
undid the space encoding (%20), so file/directory names containing
other special characters (e.g. some#file, some&file) were returned
with escaped characters embedded in the path.

Fix: unescape the entire relative URI string with
Uri.UnescapeDataString instead of only replacing %20.

Added tests covering #, %, and & characters in UtilsSpecs.fs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant