Skip to content

Conversation

@notAreYouScared
Copy link
Member

Closes #1553

@notAreYouScared notAreYouScared self-assigned this Sep 4, 2025
@coderabbitai
Copy link

coderabbitai bot commented Sep 4, 2025

📝 Walkthrough

Walkthrough

Introduces a new encode_path helper to URL-encode each path segment and updates ListFiles.php to apply encode_path to non-directory file URLs for record, view, edit, and download actions. Directory handling remains unchanged.

Changes

Cohort / File(s) Change Summary
URL encoding in file list actions
app/Filament/Server/Resources/FileResource/Pages/ListFiles.php
Wrapped join_paths(...) with encode_path(...) for non-directory file URLs in recordUrl, and in view, edit, and download action URLs.
Helper utilities
app/helpers.php
Added global function encode_path(string $path): string that rawurlencode-s each path segment and rejoins with '/'.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant UI as ListFiles (UI)
  participant H as encode_path()
  participant R as Router
  participant C as Files Controller

  U->>UI: Click "Download" on file with special chars
  UI->>H: encode_path(join_paths(path, filename))
  H-->>UI: Encoded path
  UI->>R: GET /files/download/{encoded path}
  R->>C: Route to download action
  C-->>U: File response
  note over UI,R: Same encoding applied for record, view, and edit URLs
Loading

Assessment against linked issues

Objective Addressed Explanation
Handle filenames with special characters (e.g., {}) without 500 by correctly passing route parameter (#1553)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@notAreYouScared notAreYouScared changed the title url encode encode speical characters in urls Sep 4, 2025
@rmartinoscar rmartinoscar changed the title encode speical characters in urls Encode special characters in File Manager urls Sep 4, 2025
@Boy132 Boy132 changed the title Encode special characters in File Manager urls Encode file path in url Sep 4, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (9)
app/Filament/Server/Resources/FileResource/Pages/ListFiles.php (9)

70-76: Encode breadcrumb links when building URLs

Breadcrumb links currently pass raw path (Line 73). If a segment contains “{}”, the generated URL can still break. Encode before passing to getUrl.

Update Line 73:

$breadcrumbs[self::getUrl(['path' => encode_path(ltrim($previousParts, '/'))])] = $part;

170-178: Encode path on redirects back to ListFiles

Several redirects construct ListFiles::getUrl(['path' => $this->path]) without encoding; this can reintroduce the bug for “{}”. Encode in these spots:

  • Line 177
return redirect(ListFiles::getUrl(['path' => encode_path($this->path)]));

300-308: Same redirect encoding needed after archive

Encode the ‘path’ parameter in the redirect.

  • Line 307
return redirect(ListFiles::getUrl(['path' => encode_path($this->path)]));

326-328: Same redirect encoding needed after unarchive

  • Line 327
return redirect(ListFiles::getUrl(['path' => encode_path($this->path)]));

396-401: Same redirect encoding needed after bulk archive

  • Line 399
return redirect(ListFiles::getUrl(['path' => encode_path($this->path)]));

520-523: Same redirect encoding needed after upload/pull

  • Line 522
return redirect(ListFiles::getUrl(['path' => encode_path($this->path)]));

446-449: Encode path when redirecting after “file already exists”

  • Line 448
$this->redirect(self::getUrl(['path' => encode_path(dirname($path))]));

486-491: Encode path when redirecting after “folder already exists”

  • Line 489
$this->redirect(self::getUrl(['path' => encode_path(dirname($path))]));

566-569: Encode path for SearchFiles URL as well

Search page receives a ‘path’ parameter too; encode it to keep behavior consistent.

  • Lines 566–569
->action(fn ($data) => redirect(SearchFiles::getUrl([
    'searchTerm' => $data['searchTerm'],
    'path' => encode_path($this->path),
])))
🧹 Nitpick comments (2)
app/helpers.php (1)

114-119: encode_path: correct per-segment encoding; add docblock + tests for edge cases

Good choice using rawurlencode on each segment; this preserves “/” while safely encoding “{}”, spaces, etc. Please add a brief docblock (usage: route param building, not filesystem ops) and unit tests covering: "{}", spaces, "#", "+", "%", leading/trailing slashes, and multi-segment inputs.

I can draft the docblock and PHPUnit tests if you want.

app/Filament/Server/Resources/FileResource/Pages/ListFiles.php (1)

108-118: DRY: centralize route-path encoding

To prevent future misses, add a tiny helper on this page and use it wherever building URLs:

private function routePath(string $path): string
{
    return encode_path(ltrim($path, '/'));
}

Then replace array keys like ['path' => encode_path(join_paths(...))] with ['path' => $this->routePath(join_paths(...))].

Also applies to: 125-131, 180-185

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 079eaed and 337b9ed.

📒 Files selected for processing (2)
  • app/Filament/Server/Resources/FileResource/Pages/ListFiles.php (2 hunks)
  • app/helpers.php (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
app/Filament/Server/Resources/FileResource/Pages/ListFiles.php (3)
app/Filament/Server/Resources/FileResource/Pages/EditFiles.php (2)
  • EditFiles (40-259)
  • getUrl (244-247)
app/helpers.php (2)
  • encode_path (115-118)
  • join_paths (53-60)
app/Filament/Server/Resources/FileResource/Pages/DownloadFiles.php (1)
  • DownloadFiles (19-71)
🔇 Additional comments (3)
app/Filament/Server/Resources/FileResource/Pages/ListFiles.php (3)

125-125: LGTM: directory “view” action now URL-safe

Using encode_path here ensures “{}” and other specials don’t break navigation.


130-130: LGTM: edit action path encoding is correct

This aligns with EditFiles route expecting an encoded ‘path’ segment.


184-184: LGTM: download action path encoding matches DownloadFiles::mount(rawurldecode())

This prevents curly-brace routes from failing while remaining compatible with rawurldecode in DownloadFiles.

}

return $file->canEdit() ? EditFiles::getUrl(['path' => join_paths($this->path, $file->name)]) : null;
return $file->canEdit() ? EditFiles::getUrl(['path' => encode_path(join_paths($this->path, $file->name))]) : null;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Encode directory record URL too to avoid inconsistent behavior and possible 500s

You’ve encoded file record URLs; do the same for directories (Line 110) so clicking the row for a directory named with “{}” can’t trip the router.

Change on Line 110:

return self::getUrl(['path' => encode_path(join_paths($this->path, $file->name))]);
🤖 Prompt for AI Agents
In app/Filament/Server/Resources/FileResource/Pages/ListFiles.php around line
117, the URL returned for directory rows is not being passed through
encode_path, which can cause router errors for names with special characters;
update the directory branch to wrap join_paths($this->path, $file->name) with
encode_path before calling self::getUrl (i.e., call self::getUrl(['path' =>
encode_path(join_paths(...))]) ) so directories are encoded the same way as
files.

@notAreYouScared notAreYouScared merged commit 2952e22 into main Sep 4, 2025
25 checks passed
@notAreYouScared notAreYouScared deleted the issue/1553v2 branch September 4, 2025 21:15
@github-actions github-actions bot locked and limited conversation to collaborators Sep 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File name with {} causes 500 error

3 participants