Skip to content

Guard remaining nil/invalid request params in version and config-search routes to prevent 500s#3

Merged
makaiver merged 2 commits into
fix/nil-group-param-nomethoderrorfrom
copilot/fixnil-group-param-nomethoderror-another-one
Jun 1, 2026
Merged

Guard remaining nil/invalid request params in version and config-search routes to prevent 500s#3
makaiver merged 2 commits into
fix/nil-group-param-nomethoderrorfrom
copilot/fixnil-group-param-nomethoderror-another-one

Conversation

Copilot AI commented Jun 1, 2026

Copy link
Copy Markdown
  • Guard route_parse against nil params (use params[param].to_s.split('.'))
  • Guard /node/version against missing node_full param
  • Guard /nodes/conf_search against missing/blank input and rescue RegexpError
  • Add spec/web/conf_search_spec.rb regression specs (missing & malformed inputs)
  • Add /node/version no-node_full regression spec
  • Update existing get_version mock expectations to nil group (matches fix: normalize nil group param to prevent NoMethodError ytti/oxidized-web#441 behavior)
  • Append CHANGELOG entry under ## [Unreleased]### Fixed
  • bundle exec rake → 47 runs, 0 failures, RuboCop clean
Original prompt

Goal

Extend the existing PR ytti#441 by committing directly onto its head branch fix/nil-group-param-nomethoderror in this fork (makaiver/oxidized-web). Do NOT create a new branch and do NOT open a new pull request — push commits onto fix/nil-group-param-nomethoderror so they appear in the already-open PR ytti#441.

PR ytti#441 already fixed a NoMethodError when the group= param is absent from /node/version/view and /node/version/diffs. That fix is correct but incomplete: several sibling request params on the same and adjacent routes are still used without a nil-guard and each crashes the app with HTTP 500 on a single unauthenticated request. Build on top of the existing changes — do NOT revert or duplicate the existing group normalization (params[:group] || '' and the .empty? ? nil : ... / group = nil if ... logic) or the two specs already added in spec/web/node/version_spec.rb.

Empirically confirmed crashes (all return HTTP 500 on current branch head)

Request Exception Location in lib/oxidized/web/webapp.rb
GET /node/version/view?oid=...&epoch=...&num=2 (no node=) NoMethodError: undefined method 'split' for nil route_parseparams[param].split
GET /node/version/diffs?oid=...&epoch=...&num=2 (no node=) NoMethodError: undefined method 'split' for nil route_parseparams[param].split
GET /node/version (no node_full=) NoMethodError: undefined method 'include?' for nil node_full.include? '/' (~line 145-146)
POST /nodes/conf_search (no search_in_conf_textbox) TypeError: no implicit conversion of nil into String Regexp.new params[:search_in_conf_textbox] (~line 67-68)
POST /nodes/conf_search with search_in_conf_textbox=( RegexpError: end pattern with unmatched parenthesis Regexp.new params[:search_in_conf_textbox]

The group param (already fixed by ytti#441) is the control and does NOT crash.

Required code changes in lib/oxidized/web/webapp.rb

  1. Guard route_parse against a nil param. It currently does params[param].split '.', which raises when params[param] is nil. Normalize nil to an empty string before splitting (e.g. params[param].to_s.split('.')) so a missing param yields ['', false] instead of crashing. Preserve existing behavior for present params and the .json suffix detection (including the branch where param.respond_to?(:to_str)). This makes /node/version/view and /node/version/diffs return a normal (non-500) response when node is absent.

  2. Guard node_full on GET /node/version.?:format?. node_full = params[:node_full] then if node_full.include? '/' crashes when nil. Use params[:node_full].to_s (or an explicit nil-guard) so an absent node_full is treated as an empty node name. Preserve the existing group/node splitting when a / is present.

  3. Guard conf_search on POST /nodes/conf_search.?:format?. @to_research = Regexp.new params[:search_in_conf_textbox] crashes on nil (TypeError) and on malformed regex like ( (RegexpError). Normalize a missing/blank search term (return an empty result set instead of crashing) and wrap the Regexp.new so a malformed user pattern returns a clean response (empty results) rather than a 500 — rescue RegexpError (and handle nil/blank up front). Keep the existing valid-input search behavior. Note this is also a minor DoS surface (unvalidated user regex), so failing safe matters.

Do not change unrelated behavior. Keep ytti#441's group handling intact.

Tests — spec/web/node/version_spec.rb (+ conf_search spec if needed)

The repo uses minitest + rack-test + mocha. Mirror the style of the two specs already added in ytti#441 (e.g. it 'returns 200 when group param is absent (no NoMethodError)'). Use @nodes = mock('Oxidized::Nodes') and set expects(...) only for backend calls that should still occur after the guard. For routes that crash before any backend call, set expectations so mocha doesn't fail on unmet/unexpected calls. For conf_search, the handler iterates nodes.list, so stub @nodes.expects(:list).returns([]) to isolate it.

Add specs asserting a non-500 response after the fix for:

  • /node/version/view without node=
  • /node/version/diffs without node=
  • /node/version without node_full=
  • POST /nodes/conf_search without search_in_conf_textbox
  • POST /nodes/conf_search with malformed regex search_in_conf_textbox=(

Run bundle exec rake test and ensure the whole suite (including existing tests) passes.

Rubocop

Run rubocop (try rubocop -A / --autocorrect) and ensure the final diff has no new offenses, respecting .rubocop.yml (plugins: rubocop-rails, rubocop-rake, rubocop-minitest; Style/StringLiterals disabled, Style/FrozenStringLiteralComment disabled, verbose hash methods, Layout/LineLength disabled).

CHANGELOG.md

Append a new bullet to the existing ### Fixed section under `...

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Fix additional NoMethodError in node version requests Guard remaining nil/invalid request params in version and config-search routes to prevent 500s Jun 1, 2026
Copilot AI requested a review from makaiver June 1, 2026 08:22
@makaiver
makaiver marked this pull request as ready for review June 1, 2026 08:33
@makaiver
makaiver merged commit 56a7f37 into fix/nil-group-param-nomethoderror Jun 1, 2026
@makaiver
makaiver deleted the copilot/fixnil-group-param-nomethoderror-another-one branch June 1, 2026 08:34
Copilot stopped work on behalf of makaiver due to an error June 1, 2026 08:34
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