Skip to content

Normalize router paths by removing leading slashes#382

Open
apapacy wants to merge 1 commit into
novaframework:masterfrom
apapacy:fix-filename-join-leading-slash
Open

Normalize router paths by removing leading slashes#382
apapacy wants to merge 1 commit into
novaframework:masterfrom
apapacy:fix-filename-join-leading-slash

Conversation

@apapacy
Copy link
Copy Markdown

@apapacy apapacy commented May 11, 2026

PR: Normalize router paths by removing leading slashes

Summary

Fixed an issue in the router where filename:join/1 was incorrectly processing paths due to a persistent leading slash. Previously, the leading slash caused the function to treat the segment as an absolute path, effectively discarding the base directory.

The Problem

In Erlang, filename:join/1 has a specific behavior: if an element in the list starts with a directory separator (a leading slash), it is treated as an absolute path. This causes filename:join to ignore all preceding elements in the list.

Example of the bug:

%% If LocalPath is "/static/item.png"
filename:join(["/app/priv", "/static/item.png"]).
%% Result: "/static/item.png" (The "/app/priv" part is lost)

Because of this, the logic was unintentionally biased towards the LocalPath value, bypasssing the intended directory nesting.

Changes

  • Implemented leading slash removal for incoming path segments before joining.
  • Utilized string:trim(Path, leading, "/") (or pattern matching) to ensure the path is treated as relative to the application's priv_dir.

Impact

  • Current Logic: This change has no immediate negative impact on existing functionality, as the resolved paths still point to the correct files in the current environment.
  • Future Proofing: This is a preemptive fix. It ensures that future code changes—such as shifting base directories, adding nested prefixes, or modifying how priv_dir is structured—will behave predictably. It resolves a "silent bug" before it becomes a breaking issue.

Technical Notes

By normalizing the path to a relative string, filename:join now correctly concatenates the segments:

%% After fix:
filename:join(["/app/priv", "static/item.png"]).
%% Result: "/app/priv/static/item.png" (Correct)

Key terms used:

  • Leading slash: Слэш на початку рядка.
  • Preemptive fix: Виправлення "наперед" (профілактичне).
  • Predictably: Передбачувано.
  • Discarding: Відкидання (ігнорування) частини шляху.

@apapacy apapacy requested a review from Taure as a code owner May 11, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant