-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Simple formatting cleanup over Uri #31874
Conversation
@@ -49,7 +37,7 @@ internal static string ParseCanonicalName(string str, int start, int end, ref bo | |||
// | |||
// Assumption is the caller will check on the resulting name length | |||
// Remarks: MUST NOT be used unless all input indexes are verified and trusted. | |||
internal static unsafe bool IsValid(char* name, ushort start, ref int returnedEnd, bool notImplicitFile) | |||
public static unsafe bool IsValid(char* name, ushort start, ref int returnedEnd, bool notImplicitFile) |
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 is the only one I'm not sure of; I've seen this inconsistency elsewhere and not sure if we have a recommendation.
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.
not sure if we have a recommendation.
It might not be written down but the recommendation is to use 'internal' for classes that need to be used throughout the assembly (i.e. System.Private.Uri) but then use only 'public' or 'private' for methods, properties, etc.
|
||
Uri resultUri = new Uri(baseUri, testUri); | ||
|
||
throwAway = resultUri.Port; // For Debugging. | ||
_ = resultUri.Port; // For Debugging. |
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.
What does the // For Debugging
comment mean? Is this functionally necessary? It sounds like it is for the port one above.
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.
The code pattern above was probably used because there is a side-affect of doing a 'get' on the .Port property.
Will the behavior be the same if you use "_"?
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.
As far as I am aware, the behavior is the same as assigning to a dummy local, but it makes it obvious which values aren't used and avoids analyzer warnings
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.
@MihaZupan, I'm still not clear on what the "For Debugging" comment is referring 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.
Thinking about it more, I think this is a possible reason why it was used:
Uri is currently parsed in 3 phases (lazy):
- In the ctor - identify the type of Uri, check the authority and other basic things to determine if the Uri is valid
- Determine offsets for UserInfo, Host, Path, parse the port value
- Determine the rest of offsets (Query, Fragment) and check if parts are in canonical form
This can make debugging harder. For example when debugging in Visual Studio, you must be careful to explicitly turn off the feature showing Locals - you can be stepping through the ctor and VS tries to evaluate properties like Query which trigger full parsing (before the initial ctor parsing even started), thus corrupting the Uri state under the debugger.
I've hit this when debugging Uri before and it took me a few hours to realize what was happening.
If the original author was debugging this code, they could have used code like
_ = uri.Port
Debugger.Launch();
to force more parsing before attaching the debugger, but forgot to remove it afterwards.
I've removed it.
src/libraries/System.Private.Uri/tests/FunctionalTests/IriTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.Uri/tests/FunctionalTests/UriBuilderParameterTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.Uri/tests/FunctionalTests/UriIpHostTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.Uri/tests/FunctionalTests/UriMailToTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.Uri/tests/FunctionalTests/UriMailToTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.Uri/tests/FunctionalTests/UriParameterValidationTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.Uri/tests/FunctionalTests/UriParameterValidationTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.Uri/tests/FunctionalTests/UriParameterValidationTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.Uri/tests/FunctionalTests/UriRelativeResolutionTest.cs
Outdated
Show resolved
Hide resolved
Made a second pass over test files, please re-review |
I've noticed there are still comments on this PR that don't have answers from you. It would be helpful if you could review all of those, type in appropriate comments ("Fixed", "Not really a problem", etc.) and then click "Resolve" on the issue. That helps reviewers more quickly be able to re-review a PR. Thanks! |
d94eee8
to
d6101cb
Compare
src/libraries/System.Private.Uri/tests/FunctionalTests/IriTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.Uri/tests/FunctionalTests/UriParserTest.cs
Outdated
Show resolved
Hide resolved
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.
Other than my remaining comments, LGTM.
d6101cb
to
c5ff762
Compare
Usings, inline out params, indentation, discards etc (these aren't all such cases in Uri, I am just trying to split my changes into more reviewable chunks).
No behavioral changes.