-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Simplify DocumentUri implementation #81951
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
| } | ||
| else | ||
| { | ||
| return Uri.Equals(this.ParsedUri, otherUri.ParsedUri); |
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.
note Uri.Equals doesn't exist. it calls through to object.Equals
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 am pretty sure Uri.Equals exists and I am pretty sure we need to use it in some cases to handle casing - https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.Uri/src/System/Uri.cs#L1745
| } | ||
| else | ||
| { | ||
| return Uri.Equals(this.ParsedUri, otherUri.ParsedUri); |
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 am pretty sure Uri.Equals exists and I am pretty sure we need to use it in some cases to handle casing - https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.Uri/src/System/Uri.cs#L1745
That's instance Equals. But this is the static Equals(a, b) being called. Taht has a very simple impl which just does some null checking, and then calls into instance .Equals. So the prior code was correct, as is the new code. It's just that saying |
ah of course, for some reason I read |
| private Optional<Uri> _parsedUri; | ||
|
|
||
| public DocumentUri(string uriString) | ||
| public DocumentUri(Uri parsedUri) : this(parsedUri.AbsoluteUri) |
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 don't think this is always correct. Nothing is constraining the System.Uri to be an absolute uri,, it could be relative and AbsoluteUri will throw
I think that also even round tripping an absolute URI like this could change how it is parsed - for example possibly percent encoding the Uri twice.
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 def agree. though that was the existing logic:
public DocumentUri(Uri parsedUri)
{
UriString = parsedUri.AbsoluteUri;
_parsedUriLazy = new(() => parsedUri);
}
Any thoughts on what we should do?
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.
edit - the first part of my statement was wrong. it looks like its already doing AbsoluteUri below. But I believe the second still applies. I'm not sure there is a guarantee that Uri.AbsoluteUri == new Uri(Uri.AbsoluteUr)).AbsoluteUri
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.
Is it possible to keep the DocumentUri(Uri parsedUri) ctor, and assign the Uri to the Optional<Uri> like we did before?
For the absolute part, it must be the callers that guarantee an absolute URI. I would be an ok with an explicit throw if not absolute here.
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.
ooh. very good catch. i actually had that, but accidentally deleted it. it def should remain!
No description provided.