Skip to content

fix(cli): normalize nbox raw paths to /api/ and reject absolute URLs - #65

Merged
lance0 merged 1 commit into
masterfrom
fix/raw-api-path
Jun 22, 2026
Merged

lance0 merged 1 commit into
masterfrom
fix/raw-api-path

Conversation

@lance0

@lance0 lance0 commented Jun 22, 2026

Copy link
Copy Markdown
Owner

The bug

nbox raw GET dcim/devices/?limit=1 failed with decoding NetBox response... expected value at line 8 column 1, while typed commands worked against the same instance.

Root cause: run_raw passes the path to client.get → url_for does base_url.join(path.trim_start_matches('/')). A relative path without /api/ resolves against the base to the web UI (https://host/dcim/devices/), which returns HTML — hence the JSON decode error at "line 8". Typed commands work because their path literals already include /api/. Confirmed live on 4.6.2: api/dcim/... and /api/dcim/... work; bare dcim/... doesn't.

The fix

normalize_raw_path() (pure, unit-tested):

  • Roots the path at /api/ whether you write dcim/..., api/dcim/..., or /api/dcim/... — without doubling (api/api/).
  • Rejects absolute URLs / schemes (https://…, malformed http:/…): Url::join with an absolute input replaces the base, which would send raw off the configured instance. raw stays path-only against the active profile.

Tests (per review)

  • All three accepted inputs → the same api/dcim/devices/?limit=1.
  • Leading-slash-no-api, already-api/ (no double prefix), whitespace trim, a segment merely starting with api (apiserver/), and a colon in a query value.
  • Absolute / scheme inputs rejected.

Help text + AGENTS.md updated. CHANGELOG under [Unreleased] (ships with 0.9.0).

Verification

fmt · clippy (--all-features + --no-default-features, -D warnings) · tests both modes — all green. Live: bare path now returns JSON; https://… rejected.

A bare 'raw GET dcim/devices/?limit=1' joined against the base URL and hit
the web UI (https://host/dcim/devices/) → HTML → 'expected value at line N',
while typed commands worked because their path literals include /api/.

normalize_raw_path() now roots the path at /api/ whether the user writes
'dcim/...', 'api/dcim/...', or '/api/dcim/...' (no double api/), and rejects
absolute URLs / schemes — Url::join with an absolute input replaces the base,
which would send the request off the configured instance. Help text + AGENTS
updated; tests cover the three accepted forms, the no-double-prefix case, a
colon in a query value, and absolute-URL rejection.
@lance0
lance0 merged commit ec457b2 into master Jun 22, 2026
4 checks passed
@lance0
lance0 deleted the fix/raw-api-path branch June 22, 2026 20:55
lance0 added a commit that referenced this pull request Jun 22, 2026
Note the navigable device interface/cable tabs (Enter opens the interface
detail) and the cable-path A↔Z diagram (naming the device at each end), in
the TUI feature bullet, the detail keymap, and the FEATURES TUI section.
AGENTS already carries the raw-path note from #65.
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