You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Blazor] Emit action attribute when not explicit. (#51130)
This change updates the server rendering logic to always emit an absolute URL for a form action when none is specified explicitly.
## Description
When as part of rendering a form, the developer does not explicitly add an `action` attribute, the framework will automatically generate one with the value of the current request URL.
Fixes#51118
## Customer Impact
When enhanced navigation is active, the URL might change while an update to the page is in progress. In such situations, if the user clicks a button and submits a form, the form might incorrectly post to the wrong URL, as the page URL might have already been updated.
Given that when the URL updates on the document is not a behavior, we have control over, we have to account for this, and to prevent it, we make sure that we always generate forms with an action attribute, which is unambiguous.
## Regression?
- [ ] Yes
- [X] No
[If yes, specify the version the behavior has regressed from]
## Risk
- [ ] High
- [ ] Medium
- [X] Low
The fix is to detect forms without an `action` attribute and emit it to the current URL. This is correct in all cases and is unambiguous.
## Verification
- [x] Manual (required)
- [X] Automated
## Packaging changes reviewed?
- [ ] Yes
- [ ] No
- [x] N/A
----
## When servicing release/2.1
- [ ] Make necessary changes in eng/PatchConfig.props
isNonRedirectedPostToADifferentUrlMessage=`Cannot perform enhanced form submission that changes the URL (except via a redirection), because then back/forward would not work. Either remove this form\'s \'action\' attribute, or change its method to \'get\', or do not mark it as enhanced.\nOld URL: ${location.href}\nNew URL: ${response.url}`;
// If this is the result of a form post that didn't trigger a redirection.
226
+
if(!isForSamePath(response)){
227
+
// In this case we don't want to push the currentContentUrl to the history stack because we don't know if this is a location
228
+
// we can navigate back to (as we don't know if the location supports GET) and we are not able to replicate the Resubmit form?
229
+
// browser behavior.
230
+
// The only case where this is acceptable is when the last content URL, is the same as the URL for the form we posted to.
231
+
isNonRedirectedPostToADifferentUrlMessage=`Cannot perform enhanced form submission that changes the URL (except via a redirection), because then back/forward would not work. Either remove this form\'s \'action\' attribute, or change its method to \'get\', or do not mark it as enhanced.\nOld URL: ${location.href}\nNew URL: ${response.url}`;
232
+
}else{
233
+
if(location.href!==currentContentUrl){
234
+
// The url on the browser might be out of data, so push an entry to the stack to update the url in place.
235
+
history.pushState(null,'',currentContentUrl);
236
+
}
237
+
}
222
238
}
223
239
240
+
// Set the currentContentUrl to the location of the last completed navigation.
0 commit comments