Skip to content

fix: normalize nil group param to prevent NoMethodError in version/di…#441

Open
makaiver wants to merge 9 commits into
ytti:masterfrom
makaiver:fix/nil-group-param-nomethoderror
Open

fix: normalize nil group param to prevent NoMethodError in version/di…#441
makaiver wants to merge 9 commits into
ytti:masterfrom
makaiver:fix/nil-group-param-nomethoderror

Conversation

@makaiver

Copy link
Copy Markdown

Pre-Request Checklist

  • Passes rubocop code analysis (try rubocop --auto-correct)
  • Tests added or adapted (try rake test)
  • User-visible changes appended to CHANGELOG.md

Description

Bug

Requesting /node/version/view or /node/version/diffs without a group= query parameter causes a 500 in the version view:

NoMethodError: undefined method `+' for nil (NoMethodError)
        lib/oxidized/web/views/version.haml:5:in `__tilt_...'

params[:group] is nil when the query string omits group=. Both route handlers in webapp.rb assigned @info[:group] = params[:group] directly. The HAML templates then check @info[:group] != '' (which is true for nil) and enter the branch that does @info[:group] + '/' + @info[:node], crashing.

Reproduction

Against oxidized/oxidized:latest (ships oxidized-web 0.18.1):

curl -v "http://<oxidized>:8888/node/version/view?node=<node>&num=1"
# → HTTP 500: NoMethodError: undefined method `+' for nil

No authentication is required and any value for node triggers it. /node/version/diffs is affected the same way.

A common workaround is to assign a group to every device in router.db so the UI/API always emits &group=..., but that is a workaround, not a fix.

Fix

Normalize params[:group] to '' when absent in both GET /node/version/view and GET /node/version/diffs, so the existing @info[:group] != '' guards in version.haml and diffs.haml behave correctly:

group: params[:group] || '',

Tests

Added focused minitest cases in spec/web/node/version_spec.rb for both routes that issue a request with no group= parameter and assert a 200 plus the no-group branch of the template being rendered. bundle exec rake passes (rubocop + full minitest suite).

makaiver and others added 4 commits May 27, 2026 10:07
…ffs views

When a request is made to /node/version/view or /node/version/diffs
without a group= query parameter, params[:group] returns nil.
The HAML templates check `@info[:group] != ''` which evaluates to
true for nil, then attempt `nil + '/' + node` causing:

  NoMethodError: undefined method `+' for nil

Fix by normalizing params[:group] to '' when absent using `|| ''`,
so the existing guards in the templates behave correctly.
Also pass nil to get_version when group is empty, preserving the
original API contract.

Verified against oxidized/oxidized:latest (oxidized-web 0.18.1):
  curl "http://localhost:8888/node/version/view?node=test&num=1"
  Before: HTTP 500 NoMethodError
  After:  no crash
The /node/version/diffs route correctly normalises params[:group] to ''
and builds a local `group` variable (nil or value) for nodes.version,
but then passed @info[:group] (which is '' for ungrouped nodes) directly
to both nodes.get_diff calls.

In oxidized's yield_repo_and_path, an empty string is truthy, so the
path was built as "/node-name" instead of "node-name", causing get_diff
to silently return 'no diffs' for all ungrouped nodes.

Fix: use the already-correct local `group` variable in both get_diff calls.
- spec/web/node/version_spec.rb: add three tests covering the case where
  group= is entirely absent from the query string for /node/version/view
  and /node/version/diffs (the original NoMethodError scenario)
- CHANGELOG.md: add Fixed entry under [Unreleased] for the nil group
  param NoMethodError fix
Copilot AI and others added 3 commits May 27, 2026 17:12
…oderror-again

Handle missing `group` param in version routes and align branch files with RuboCop
Copilot AI and others added 2 commits June 1, 2026 08:30
…oderror-another-one

Guard remaining nil/invalid request params in version and config-search routes to prevent 500s
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.

2 participants