-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Fix #18539 - add Blazor catch-all route parameter #24038
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks great!
Maybe it would be good to add a couple of E2E tests to validate the encoding bit here
This commit can be used as a reference on what to change to add an E2E test for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the E2E tests!
This looks great!
I'll merge once the build passes. Thanks again @zbecknell for the contribution!
Hopefully those will pass @javiercn, I get this message at the end of running tests on my Mac:
|
@zbecknell Yep, we haven't gotten around to enable selenium cross-plat. The setup is quite painful to do, so we mostly run on Windows/chromium |
[Fact] | ||
public void CanArriveAtPageWithCatchAllParameterWithoutEscapedSlashes() | ||
{ | ||
SetUrlViaPushState("/WithCatchAllParameterWithoutEscapedSlashes/life/the/universe/and/everything = 42"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this here might need to be in escaped syntax so that we can see the difference. I think that's why the tests are failing. On this one you should see the unescaped value, on the one above you should see the same value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok, I did notice another call to SetUrlViaPushState
had encoded values. I'll get that changed.
Ok, pretty easy to see what's happening. I guess my first question should've been: do we expect the full value to be encoded? I didn't catch any tests that show this yet, but I may've missed them. Current behavior:
What is our desired behavior? |
It's not about encoding, it's about decoding. If the url has encoded segments on it, using |
else | ||
{ | ||
catchAllValue = string.Join('/', context.Segments[Range.StartAt(Template.Segments.Length - 1)]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized now that I overlooked this. We should be using Uri.UnescapeDataString here. It is likely that the previous behavior for *
was to not do anything, which should have not been the case, as that's the behavior **
has on ASP.NET Core routing.
I think I need to think about this a bit more, and chat with some other folks on the team, since this is a small breaking change, and I just want to make sure we are ok with it before we take it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think previously *
would be completely rejected in a template, right? So for Blazor routing we aren't introducing a breaking change, to my knowledge. I do understand the problem now, I seem to have had it backward in my head, so I can at least start by updating to unescape these segments while you double-check with the team.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, I had a brainfreeze :). So no breaking change, we should just make sure the behavior matches the one in ASP.NET Core routing, which is *
decodes the url, and **
does not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, *
and **
I believe are used for link generation, which might not apply here. Give me a second to confirm, it's been a while since I've looked at this specifically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh, **
is used for link generation... so I've really mangled my interpretation of what needs to happen here. In this case, I can just decode the entire catch-all value when it's incoming. And I don't really need to look for **
but just *
presumably.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like I can simplify this by not worrying about **
. Also the RouteContext
already decodes the values when adding the context segments so I believe that is taken care of as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. Lets just do *
for now. We can always add **
back if we have to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Final question: do we want to throw
if a template starts with more than one *
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that way we make sure we can add it in the future without breaking anyone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! That's what I thought, just wanted to confirm.
Cleaned up now. Fingers crossed for E2E tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @zbecknell! This looks great.
I'd like to take advantage of this new feature, and assumed that it would be built as part of the nightly build feed at https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json. However, when I try I get the following exception: I referenced |
@sfmskywalker Can you open an issue with a reproduction? |
I'm able to get this working when updating to the latest nightly rc1 of both the SDK and NuGet packages @sfmskywalker. (Ignore that Preview8Repro title, just reused an existing project.) |
Summary of the changes
Addresses #18539.
Hopefully this is a useful start, @captainsafia!