Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2209 Placeholders matching must work if RouteIsCaseSensitive = false #2210

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

ggnaegi
Copy link
Member

@ggnaegi ggnaegi commented Nov 20, 2024

Fixes #2209

Proposed Changes

  • We are now performing case-insensitive matching for the path pattern, but we preserve the case for the placeholders. The verification of case sensitivity is not handled in this part of the code.
  • Adding several unit and acceptance tests to verify the behavior

@ggnaegi ggnaegi requested review from raman-m and RaynaldM November 20, 2024 19:31
@ggnaegi
Copy link
Member Author

ggnaegi commented Nov 20, 2024

@raman-m ready for review

@ggnaegi ggnaegi force-pushed the bug/case-insensitivity branch from f2e659e to aaa8dbd Compare November 20, 2024 20:16
@raman-m raman-m added bug Identified as a potential bug Routing Ocelot feature: Routing labels Nov 21, 2024
// Here we are not interested in the path itself, only the placeholders.
// Path validation is not part of this class, therefore allowing case-insensitive
// matching.
return $"^(?i){escaped}";
Copy link
Member

@raman-m raman-m Nov 21, 2024

Choose a reason for hiding this comment

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

matching must work if RouteIsCaseSensitive = false

But the option is not applied here, right?

I am trying to understand how we've lost old functionality of insensitive placeholder names...
After research I found only this code which confirms that in old version names were case insensitive:

private static bool CharactersDontMatch(char characterOne, char characterTwo)
{
return char.ToLower(characterOne) != char.ToLower(characterTwo);
}

That means placeholder names are always case insensitive.

Not an issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

@raman-m What we have lost: /blabla/bliBLI/{PlaceHolder} wil not match /blabla/blibli/{PlaceHolder} because the elements after the host name could be case sensitive, and stricly taken /blabla/bliBLI can't match /blabla/blibli. But, yes, the behavior with ^(?i) is the same as the code snippet you provided.

{
var port = PortFinder.GetRandomPort();
var route = GivenRoute(port, upstream, downstream);
route.RouteIsCaseSensitive = true;
Copy link
Member

Choose a reason for hiding this comment

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

Well... Again, I'm trying to understand entire logic.
We have only 2 places where the property is applied:

1

var template = route.RouteIsCaseSensitive
? $"^{headerTemplateValue}$"
: $"^(?i){headerTemplateValue}$"; // ignore case

2

var template = route.RouteIsCaseSensitive
? $"^{upstreamTemplate}{RegExMatchEndString}"
: $"^{RegExIgnoreCase}{upstreamTemplate}{RegExMatchEndString}";

This 2nd code snippet seems the right place where we apply case sensitivity.

Not an issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

@raman-m And we don't pass the pattern to the placeholder finder, but the original one, without the regex chars.

@raman-m raman-m added the Nov'24 November 2024 release label Nov 21, 2024
@raman-m raman-m added this to the November'24 milestone Nov 21, 2024
@ggnaegi ggnaegi merged commit fe029eb into ThreeMammals:develop Nov 21, 2024
1 check passed
@raman-m
Copy link
Member

raman-m commented Nov 22, 2024

@ggnaegi Regarding the merged commit fe029eb, there has been an override of the name/title of the PR. The significant issue is the lack of reference to the fixed bug. In the future, please maintain the original commit name while prefixing it with the reference to the issue:

- Fixing issue 2209, adding extensive set of unit and acceptance tests (#2210)
+ #2209 Placeholders matching must work if RouteIsCaseSensitive = false (#2210)

As an Administrator, I will now proceed to rectify the commit name...

@raman-m
Copy link
Member

raman-m commented Nov 22, 2024

New commit in develop is d41f8fa

@raman-m raman-m changed the title Placeholders matching must work if RouteIsCaseSensitive = false #2209 Placeholders matching must work if RouteIsCaseSensitive = false Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Identified as a potential bug Nov'24 November 2024 release Routing Ocelot feature: Routing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

routes became case-sensitive after updating from 23.3.6 to 23.4.0
2 participants