test(url_utils): compare percent-escapes case-insensitively - #630
Merged
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
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.
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.
Summary
test_url_apply_credentials_replaces_existing_credentialsfails on hosts whose libcurl writes lowercase percent-escape hex digits: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) producesp%3assdirectly. Both forms are equivalent (RFC 3986 §2.1), so this is a test-portability issue, not a behavior bug. The removed comment credited650c2987'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 exactTEST_ASSERT_EQUAL_STRING. The rest of the URL, including credential case, is still compared strictly. A blanketstrcasecmpwas 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).CURLU_URLENCODEfrom the passwordcurl_url_set()makes the test fail (Was 'rtsp://new%40user:p:ss@camera/live'), so it still catches real encoding regressions.ctestotherwise unchanged. The only remaining failures are the argv-driventest_sod_unified/test_sod_voctools, which print usage when run without arguments.Investigated, implemented and tested by Claude (Anthropic) via Claude Code, working with @davlaw.
🤖 Generated with Claude Code