Skip to content
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

Avoid duplicated URL in the ODataRequest.ToString method. #153

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/SenseNet.Client.Tests/UnitTests/ODataRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,34 @@ public void ActionRequest_NoOperation()

#endregion

#region Bug fixes

[TestMethod]
public void ODataRequest_ToString_FIX_152_DuplicatedSlash()
{
var url = "https://example.com";

var server = new ServerContext { Url = url };
var request = new ODataRequest(server) { Path = "/Root/Content", ActionName = "Action1" };
Assert.AreEqual("https://example.com/OData.svc/Root('Content')/Action1?metadata=no", request.ToString());

server = new ServerContext { Url = url };
request = new ODataRequest(server) { ContentId = 42, ActionName = "Action1" };
Assert.AreEqual("https://example.com/OData.svc/content(42)/Action1?metadata=no", request.ToString());

url = "https://example.com/";

server = new ServerContext { Url = url };
request = new ODataRequest(server) { Path = "/Root/Content", ActionName = "Action1" };
Assert.AreEqual("https://example.com/OData.svc/Root('Content')/Action1?metadata=no", request.ToString());

server = new ServerContext { Url = url };
request = new ODataRequest(server) { ContentId = 42, ActionName = "Action1" };
Assert.AreEqual("https://example.com/OData.svc/content(42)/Action1?metadata=no", request.ToString());
}

#endregion

//#region LoadReferenceRequest_*

[TestMethod]
Expand Down
2 changes: 1 addition & 1 deletion src/SenseNet.Client/ODataRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ private string GetItemUrlBase()
{
// short url format that contains only the id
if (ContentId > 0)
return $"{SiteUrl}/{SERVICE_NAME}/content({ContentId})";
return $"{SiteUrl.TrimEnd('/')}/{SERVICE_NAME}/content({ContentId})";

// regular url that contains the content path
var path = Path.TrimStart('/');
Expand Down