-
Notifications
You must be signed in to change notification settings - Fork 67
Add System.Web.VirtualPathUtility #179
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
Add System.Web.VirtualPathUtility #179
Conversation
twsouthwick
left a comment
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.
This looks really good! It's reassuring seeing those tests that behavior is aligned :)
src/Microsoft.AspNetCore.SystemWebAdapters/Microsoft.AspNetCore.SystemWebAdapters.csproj
Outdated
Show resolved
Hide resolved
test/Microsoft.AspNetCore.SystemWebAdapters.Tests/VirtualPathUtilityTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.AspNetCore.SystemWebAdapters.Tests/VirtualPathUtilityTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.AspNetCore.SystemWebAdapters.Tests/VirtualPathUtilityTests.cs
Show resolved
Hide resolved
twsouthwick
left a comment
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.
nit: some whitepace issues
test/Microsoft.AspNetCore.SystemWebAdapters.Tests/VirtualPathUtilityTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.AspNetCore.SystemWebAdapters.Tests/VirtualPathUtilityTests.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.SystemWebAdapters/VirtualPathUtility.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.SystemWebAdapters/VirtualPathUtility.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.SystemWebAdapters/VirtualPathUtility.cs
Outdated
Show resolved
Hide resolved
588fe95 to
f03fed1
Compare
I think all of these are covered in the latest update. |
src/Microsoft.AspNetCore.SystemWebAdapters/Microsoft.AspNetCore.SystemWebAdapters.csproj
Outdated
Show resolved
Hide resolved
|
@CZEMacLeod there may be a delay in merging this per the comment here #83 (comment). @adityamandaleeka can provide an update here |
|
While we're waiting - do you think that #185 would help with some of the testing of non-default virtual directories? |
|
@twsouthwick I'm not sure it does anything here. All the tests pass a fixed app virtual path rather than using the overload that defaults to the HttpRuntime value. |
I'd say that's a relatively low priority. The policy I've followed is to verify certain behavior happens on framework, and then create tests to mimic that as closely as possible using what we need to mock it up locally
We've been using Moq for mocking and Autofixture for generating test data (if needed).
Yup, that's the point of #185 to add the ability to do that. The VirtualPathUtility can follow a similar pattern and be an instance class internally that takes in an IHttpRuntime and is set by the IApplicationBuilder similar to the runtime. |
|
@CZEMacLeod Can you please include the following file in your PR? https://github.com/dotnet/systemweb-adapters/blob/tasou/license/THIRD-PARTY-NOTICES.txt Once that's in we can move forward with the PR. Thanks for your patience. |
|
I don't understand why these tests failed this time round - they worked previously, and the only change was adding the text file. |
|
Try merging locally and see if it changes things. I believe the builds merge with main and build/test that |
twsouthwick
left a comment
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.
@CZEMacLeod In comparing with the framework sources, looks like you pulled in the implementation needed. Would it be much work to keep the implementation using UrlPath, VirtualPath, StringUtil and the other helper classes as is? Additional infrastructure we may want to bring in will be using those as well and it would be nice to keep the similar shape so as we bring in more stuff we don't start duplicating stuff.
I only brought in a small part of |
Yeah, the challenge is that a lot of stuff internally ends up relying on these methods/classes. It will simplify future work to bring stuff in in the same shape and then we can deal with any perf impacts en masse (i.e. VirtualPath could be converted to use spans/be a struct/etc). I'd really prefer that this happens as part of this PR, otherwise, I'll probably end up needing to redo it to support that scenario. No need to bring in the whole classes - just the parts you used. When you say "didn't bring in VirtualPath" at all, you mean you inlined it, right? All the implementation at https://referencesource.microsoft.com/#System.Web/VirtualPathUtility.cs,2b829f9059f552ca shows things being delegated to
Looks like your merge may have done something weird. It's showing files that are in the project already as being additions. Maybe try rebasing and force pushing? |
|
@twsouthwick The implementation of As for the merge stuff - yeah. I had to pull in the changes from #185 due to the changes to (I)HttpRuntime, then it thought there were merge conflicts for a file I didn't touch, so I brought in the other changes from #186 so it would merge correctly. I think it is fine now, but I can try rebasing it again if needed. |
|
Ok - I think I understand now. For now, then, can you put the methods you pulled from
I'm still seeing a bunch of erroneous changes. It may be GitHub showing the diff weird, but can you try rebasing? |
|
I'm looking at breaking out the |
…e.SystemWebAdapters.csproj Co-authored-by: Taylor Southwick <[email protected]>
This reverts commit 4f07395.
78f4a21 to
bd6cf61
Compare
|
@twsouthwick I've broken out the methods into the util classes, and rebased. Hopefully this will a) merge correctly without whatever weirdness you were seeing and b) build, and test correctly (it does locally). |
twsouthwick
left a comment
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.
LGTM! Thanks @CZEMacLeod for the contribution and working to get it ready to merge.
There's definitely room for improvement as you pointed out in the StringUtil and UrlPath classes, but it will allow to bring in more functionality more easily as so much code in System.Web ends up relying on these helpers. These methods can receive some targeted fixes in the future. (some of them look even like they're probably built-in functions that could do it now)
Yup on both accounts :) I've seen that weirdness with GH when doing merges. Not exactly sure why, but rebasing seems to fix it. |
|
|
||
| internal static bool HasTrailingSlash(string virtualPath) => virtualPath[^1] == '/'; | ||
|
|
||
| internal static bool IsRooted(string basepath) => string.IsNullOrEmpty(basepath) || basepath[0] == '/' || basepath[0] == '\\'; |
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.
Empty is rooted?
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 is according to the original code - https://github.com/microsoft/referencesource/blob/master/System.Web/Util/UrlPath.cs#L33
Null or Empty tends to get caught further up in the calls in VirtualPathUtility and either returns something explicit or throws.
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.
FYI These methods are taken as-is (mostly) from System.Web and is how they handled things. Not sure how well we can reason about some of these things :)
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 - UrlPath and StringUtil (other than code optimizations based on newer c# / .net functions and error strings) are pretty much a direct port.
| // e.g c:\foo | ||
| if (path[1] == ':' && IsDirectorySeparatorChar(path[2])) return true; |
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.
This allows \:\. What restrictions should be checked for the first character?
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.
Again - this is based on the original code. I'm not sure there is ever a reason that something like \:\ would be allowed as a virtual path - the use of this function is to throw if it is not a valid virtual path in CheckValidVirtualPath.
src/Microsoft.AspNetCore.SystemWebAdapters/Utilities/UrlPath.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.SystemWebAdapters/Utilities/UrlPath.cs
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| // Same as Reduce, but for a virtual path that is known to be well formed | ||
| internal static string ReduceVirtualPath(string path) |
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.
could this path contain escaped dots or slashes?
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.
Unless the original call did, I don't think so. This is mainly used with the result of MakeVirtualPathAppAbsolute or MakeRelative which would normally be called with hardcoded strings from the developer, and possibly the current request path, which I think should also be 'clean'.
As it says in the description - only use on a virtual path that is known to be well formed.
This code is pretty much untouched from the original .Net implementation, other than some changes to substring handling and error messages.
If it needs to be made more robust than the original, then I think that is a separate issue?
Style: always use the brackets Co-authored-by: Chris Ross <[email protected]>
9a5d3ca to
7d4b4b0
Compare
Add System.Web.VirtualPathUtility implementation for AspNet Core
Add an implementation of System.Web.VirtualPathUtility based on the codebase for net framework
Adds System.Web.VirtualPathUtility based (in part) on
System.Web.Util.UrlPath code at https://github.com/microsoft/referencesource/blob/master/System.Web/Util/UrlPath.cs
System.Web.Util.StringUtil at https://github.com/microsoft/referencesource/blob/master/System.Web/Util/StringUtil.cs
Addresses #83