Fix NoMethodError in FilesController when Accept header is missing (#5447)#5448
Merged
Merged
Conversation
FilesController#fs starts with:
request.format = 'json' if request.headers['HTTP_ACCEPT'].split(',').include?('application/json')
If the request has no Accept header (for example, Chrome's <a download>
link sometimes omits it when fetching a file referenced by an Interactive
App session view), HTTP_ACCEPT is nil and nil.split raises
NoMethodError. The exception is rescued by rescue_action, which silently
redirects the user to $HOME instead of returning the file.
Use safe navigation on both the split and the include? so a missing
Accept header simply leaves the default request format alone (Rails's
normal content negotiation then picks html).
johrstrom
reviewed
May 11, 2026
johrstrom
reviewed
May 11, 2026
added 2 commits
May 12, 2026 12:48
Per reviewer feedback:
- CHANGELOG updates are handled by release automation, drop the hunk.
- Prefer .to_s.split(',').include?(...) over &.split(',')&.include?(...)
for readability and consistency with other code in the codebase.
Array#include? returns true/false, never nil, so the original 'returns nil when Accept header is missing' test could never pass (CI failed with 'Expected false to be nil.' on Ruby 3.1-3.4). Rename and switch to refute, matching the symmetric 'returns falsy when Accept does not include application/json' test below it.
Bubballoo3
approved these changes
May 20, 2026
Contributor
Bubballoo3
left a comment
There was a problem hiding this comment.
Tested and works well!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #5447
Bug
FilesController#fsstarts with:If the incoming request has no
Acceptheader,request.headers['HTTP_ACCEPT']isnil,nil.splitraisesNoMethodError, the globalrescue_actioncatches it, and the user is redirected to$HOMEinstead of being served the file.How it was hit
Building an Interactive App whose
view.html.erblinks to a session-specific file with<a download href="/pun/sys/dashboard/files/api/v1/fs<%= abs_path %>">. Chrome 147 on macOS omitsAccepton download clicks; error.log filled withundefined method 'split' for nil:NilClass. Full context in #5447.Fix
Extract the Accept-header check into a
json_request?helper that safe-navigates the split and include?. When the header is absent we simply leaverequest.formatalone and Rails's normal content negotiation pickshtml:The extraction also slightly reduces
fs's complexity scores (per rubocop: AbcSize 97.59 → 93.34, Cyclomatic 19 → 17, Perceived 25 → 23), though the method is still over the project's metric limits — preexisting debt tracked by #1187.Tests
New controller tests in
files_controller_test.rbcovering the three cases:json_request?returns nil (regression test for this issue).application/json→ returns truthy.application/json→ returns falsy.Integration-style
get :fstests would need extensive stubbing for an unrelated surface area; the direct helper test exercises the exact logic that was broken.Lint
rubocop apps/dashboard/app/controllers/files_controller.rb— no new offenses introduced; 30 preexisting offenses unchanged, four of which (onfs) actually improved slightly.Changelog
### Fixedentry added under[Unreleased].