-
Notifications
You must be signed in to change notification settings - Fork 34
Refactor URI construction and enhance test coverage #126
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,19 +22,22 @@ internal abstract class ExecutableOperation | |
| /// </summary> | ||
| /// <param name="baseAddress">The base address from the client.</param> | ||
| /// <param name="relativeOrAbsoluteUri">A relative or absolute URI</param> | ||
| /// <param name="itemId">The id of the item to append to the URI.</param> | ||
| /// <returns></returns> | ||
| internal static Uri MakeAbsoluteUri(Uri? baseAddress, Uri relativeOrAbsoluteUri) | ||
| internal static Uri MakeAbsoluteUri(Uri? baseAddress, Uri relativeOrAbsoluteUri, string? itemId = null) | ||
| { | ||
| itemId = string.IsNullOrWhiteSpace(itemId) ? string.Empty : $"/{itemId}"; | ||
|
|
||
| if (relativeOrAbsoluteUri.IsAbsoluteUri) | ||
| { | ||
| return new Uri($"{relativeOrAbsoluteUri.ToString().TrimEnd('/')}/"); | ||
| return new Uri($"{relativeOrAbsoluteUri.ToString().TrimEnd('/')}{itemId}"); | ||
| } | ||
|
|
||
| if (baseAddress != null) | ||
| { | ||
| if (baseAddress.IsAbsoluteUri) | ||
| { | ||
| return new Uri($"{new Uri(baseAddress, relativeOrAbsoluteUri).ToString().TrimEnd('/')}/"); | ||
| return new Uri($"{new Uri(baseAddress, relativeOrAbsoluteUri).ToString().TrimEnd('/')}{itemId}"); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we may need to trim the slash if it is at the end. In some scenarios, the ASP.NET Core routing middleware treats a http://server/foo/ as lexically different to http://server/foo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @adrianhall, No problem. I'll update to remove the trailing slash and update the tests. I know in my current environment all the other operations work as expected against the server. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @adrianhall hopefully that's it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope - this definitely has an issue. See this one:
If relativeOrAbsoluteUri ends with a / and itemId is set, then there is no separator. Probably better to construct a string with the right URI in it. Then |
||
| } | ||
|
|
||
|
|
||
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.
@adrianhall the separator is set here if the itemId is specified.
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 - I get it. Although, use of IsNullOrWhiteSpace does change the semantics of the method. If someone submits " ", I believe it gets rejected before this point, so should be ok.
Assuming the tests pass, I'll merge this.