Skip to content

[tests] Fix UrlEscaping_Bug43411 to actually run and assert correctly#11523

Merged
simonrozsival merged 3 commits into
mainfrom
jonathanpeppers/fix-urlescaping-bug43411
May 29, 2026
Merged

[tests] Fix UrlEscaping_Bug43411 to actually run and assert correctly#11523
simonrozsival merged 3 commits into
mainfrom
jonathanpeppers/fix-urlescaping-bug43411

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

Two issues with UrlEscaping_Bug43411 in AndroidMessageHandlerIntegrationTests on main:

  1. The test has been silently dead for years. The method was declared void UrlEscaping_Bug43411 () (non-public). NUnitLite — the legacy in-process runner used by the device test suite — silently skipped non-public [Test] methods, so this test never ran. Nobody noticed because the failure mode was "silently never runs."

    Discovered while migrating to stock NUnit 3 via dotnet test in [WIP] Dogfood dotnet test for device tests #11224, where NUnit 3 actually surfaces the method and it fails.

  2. The assertion was wrong. It compared the request URL against request.RequestUri.ToString (), but per the .NET docs Uri.ToString () returns the "human-readable" form and unescapes safe characters like %20 → literal space. So Assert.AreEqual ("http://localhost:8810/?example=value%20_value", request.RequestUri.ToString ()) fails because the actual value contains value _value with a space.

    The correct property is Uri.AbsoluteUri, which returns the canonical encoded form and preserves percent-encoding.

Changes

  • Make UrlEscaping_Bug43411 public so NUnit discovers it. The helper UrlEscaping_TestUrl stays non-public.
  • In UrlEscaping_TestUrl, switch from request.RequestUri.ToString () to request.RequestUri.AbsoluteUri, with a brief comment explaining why.

See #11224 for context on the NUnit 3 migration that surfaced this.

Two issues with this test on main:

1. The method was declared `void UrlEscaping_Bug43411 ()` (non-public). NUnitLite silently skipped non-public `[Test]` methods, so the test has been effectively dead for years. Discovered while migrating to stock NUnit 3 via `dotnet test` in PR #11224, where NUnit 3 surfaces the method and it fails.

2. The assertion compared the request URL against `Uri.ToString ()`, which returns the human-readable form and unescapes safe characters like `%20` to a literal space. The canonical, encoded form is `Uri.AbsoluteUri` — switch to that so percent-encoding is preserved.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 27, 2026 21:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a previously undiscovered AndroidMessageHandler integration test so it is run by NUnit and validates URL escaping using the encoded URI representation.

Changes:

  • Makes UrlEscaping_Bug43411 public so the test runner discovers it.
  • Updates the assertion to compare against Uri.AbsoluteUri instead of Uri.ToString().
  • Adds a short comment explaining the ToString() vs AbsoluteUri distinction.

jonathanpeppers and others added 2 commits May 28, 2026 08:11
- Make `UrlEscaping_Bug43411` (and the `UrlEscaping_TestUrl` helper) `async Task` and `await` `SendAsync` instead of blocking with `.Wait ()`.

- The previous listener callback unconditionally set `failed = true`, so `Assert.IsNull (failed)` always failed (`Expected: null, But was: True`). Capture `HttpListenerContext.Request.RawUrl` on the server side instead and compare it against the expected `Uri.PathAndQuery` — this is the verification the test was clearly meant to do (confirm that percent-encoded characters survive the round trip to the server).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers
Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@jonathanpeppers
Copy link
Copy Markdown
Member Author

New test is passing:

image

@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label May 28, 2026
@simonrozsival simonrozsival merged commit 8245ab3 into main May 29, 2026
2 of 3 checks passed
@simonrozsival simonrozsival deleted the jonathanpeppers/fix-urlescaping-bug43411 branch May 29, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants