Skip to content

Fix trie routing implementation to use ordinal comparison - #70048

Merged
Youssef1313 merged 1 commit into
mainfrom
dev/ygerges/trie
Oct 27, 2026
Merged

Youssef1313 merged 1 commit into
mainfrom
dev/ygerges/trie

Conversation

@Youssef1313

Copy link
Copy Markdown
Member

Today, the trie implementation constructs the key using ToLowerInvariant. This can cause specific unicode characters to get transformed to a lowercase ASCII character. After that, a received request using that ASCII lowercase character is going to incorrectly match which diverges from the behavior of the fallback dictionary (see DictionaryJumpTable).

This PR ensures we have consistent behavior in routing.

Fixes #70047

@Youssef1313
Youssef1313 requested a review from halter73 as a code owner October 26, 2026 09:45
Copilot AI balanced review requested due to automatic review settings October 26, 2026 09:45
@github-actions github-actions Bot added the area-routing Includes: endpoint routing and URL matching label Oct 26, 2026

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.

🔵 Needs a closer look

No concrete defects were identified, but required review evidence was unavailable and regression tests were not executed.

No open issues 🎉

What changed in this PR

This PR aligns trie routing with the dictionary fallback’s ordinal ignore-case behavior, addressing incorrect Unicode-to-ASCII matches reported in #70047.

Changes:

  • Replaces invariant lowercasing with ordinal lowercasing when constructing trie keys.
  • Adds Kelvin-sign regression cases covering different lengths and positions, exact matches, and ASCII sibling case-insensitive matches.
File Description
src/​Http/​Routing/​test/​UnitTests/​Matching/​ILEmitTrieJumpTableTest.cs Adds regression tests ensuring Kelvin-sign endpoints do not match ASCII k or K.
src/​Http/​Routing/​src/​Matching/​ILEmitTrieFactory.cs Uses ordinal lowercasing for both trie key sizes.

Review effort: Balanced

@DeagleGross DeagleGross left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Change makes sense; but I wonder if that may be a breaking change, and why the DictionaryJumpTable used Ordinal instead of Invariant in the first place (probably to match other routing)

@Youssef1313

Youssef1313 commented Oct 27, 2026 •

Copy link
Copy Markdown
Member Author

Change makes sense; but I wonder if that may be a breaking change, and why the DictionaryJumpTable used Ordinal instead of Invariant in the first place (probably to match other routing)

I doubt that such discrepancy was intentional.

ToLowerOrdinal only existed in .NET 11, which is likely the reason why ToLowerInvariant was used. I think there wasn't good of choice back then.

It's also extremely unlikely for APIs existing today to be using non-ASCII characters like the Kelvin sign which are equatable to ASCII characters when compared with invariant comparison. This reduces much the impact of this being a breaking change.

@Youssef1313
Youssef1313 merged commit f8bf4a7 into main Oct 27, 2026
32 checks passed
@Youssef1313
Youssef1313 deleted the dev/ygerges/trie branch October 27, 2026 19:46
@github-actions

Copy link
Copy Markdown
Contributor

✅ No documentation PR was created.

Confidence that documentation is needed: 5%

No docs needed: internal bug fix making trie routing use ordinal comparison, consistent with the dictionary fallback. No signals found.

Documentation surfaces considered

  • Conceptual article: Not required — Internal bug fix in the IL-emit trie routing; no public API, option, or default changes.
  • Migration guidance: Not required — No user action needed when upgrading.
  • Breaking change: Not required — Only affects obscure Unicode characters (e.g., Kelvin sign) that incorrectly matched ASCII; no documented behavior changes. Maintainers may confirm if desired.

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 05f5a803 Deployed Oct 27, 2026 by Youssef1313 via conclusion #108
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-routing Includes: endpoint routing and URL matching

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trie routing incorrectly matches endpoints using invariant culture instead of ordinal comparison

4 participants