Skip to content

test(url_utils): compare percent-escapes case-insensitively - #630

Merged
matteius merged 1 commit into
opensensor:mainfrom
davlaw:fix/url-utils-test-hex-case
Oct 6, 2026
Merged

matteius merged 1 commit into
opensensor:mainfrom
davlaw:fix/url-utils-test-hex-case

Conversation

@davlaw

@davlaw davlaw commented Oct 5, 2026

Copy link
Copy Markdown

Summary

test_url_apply_credentials_replaces_existing_credentials fails on hosts whose libcurl writes lowercase percent-escape hex digits:

Expected 'rtsp://new%40user:p%3Ass@camera/live' Was 'rtsp://new%40user:p%3ass@camera/live'

url_apply_credentials() encodes credentials through libcurl (curl_url_set(..., CURLU_URLENCODE)), so the hex case comes from libcurl, not from LightNVR. A standalone 5-line program against libcurl 8.14.1 (Debian trixie) produces p%3ass directly. Both forms are equivalent (RFC 3986 §2.1), so this is a test-portability issue, not a behavior bug. The removed comment credited 650c2987's uppercase encoder (url_utils.c:488), which is now only the fallback when libcurl can't parse the URL.

Change

Test-only. A small uppercase_percent_escapes() helper normalizes just the two hex digits after each % before the existing exact TEST_ASSERT_EQUAL_STRING. The rest of the URL, including credential case, is still compared strictly. A blanket strcasecmp was avoided because it would also accept e.g. NEW%40user.

Verification

  • test_url_utils: 15/16 → 16/16 on Debian trixie (libcurl 8.14.1). Uppercase output is unaffected (normalization is a no-op on it).
  • Mutation check: removing CURLU_URLENCODE from the password curl_url_set() makes the test fail (Was 'rtsp://new%40user:p:ss@camera/live'), so it still catches real encoding regressions.
  • Full ctest otherwise unchanged. The only remaining failures are the argv-driven test_sod_unified/test_sod_voc tools, which print usage when run without arguments.

Investigated, implemented and tested by Claude (Anthropic) via Claude Code, working with @davlaw.

🤖 Generated with Claude Code

test_url_apply_credentials_replaces_existing_credentials expected the
exact string "p%3Ass", but url_apply_credentials() encodes credentials
through libcurl (CURLU_URLENCODE), whose hex-digit case varies by
version: libcurl 8.14.1 (Debian trixie) emits "p%3ass", so the test
failed there although the URL is equivalent (RFC 3986 section 2.1).

Normalize only the two hex digits after each '%' before the exact
comparison, so the rest of the URL (including credential case) is
still checked strictly. The removed comment credited 650c298's
uppercase encoder, which is now only the parse-failure fallback.

Verified the test still fails if password encoding is removed
(got "p:ss").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The focused test-only change accepts equivalent escape casing while preserving checks for encoding regressions.

Review effort: Balanced
Findings: None

What changed in this PR

Makes the credential URL test portable across libcurl versions without changing production behavior.

Changes:

  • Normalizes percent-escape hex digits before comparison.
  • Preserves strict comparison of all other URL characters.
File Description
tests/​unit/​test_url_utils.c Adds escape normalization to the credential replacement test.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@matteius
matteius merged commit 788ec90 into opensensor:main Oct 6, 2026
1 check passed
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.

3 participants