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

Fixed issue with encoding for links.self item #225

Conversation

sergey-litvinov-work
Copy link
Contributor

Hi Jouke,

It's a follow up for already merged PR #206 . After we started to use paging, we found one issue with that old one PR. If initial query has parameters like page[number], etc, then it WebApi might encode them and then HttpRequestMessage.RequestUri would have already encoded one, and then links.self would have encoded value.

Here is what we are getting for endpoint that supports paging when we access such endpoint - https://localhost/WebService4/v5/internal/locations/marketplace?page[number]=2

{
    "data": [
        {
            "type": "marketplace-location",
            "id": "6927",
            "links": {
                "self": "https://localhost/WebService4/v5/internal/locations/locations/marketplace/6927/"
            },
            "attributes": {
                ...
            }
        }
    ],
    "links": {
        "self": "https://localhost/WebService4/v5/internal/locations/marketplace?page%5Bnumber%5D=1",
        "first": "https://localhost/WebService4/v5/internal/locations/marketplace?page[number]=0",
        "next": "https://localhost/WebService4/v5/internal/locations/marketplace?page[number]=2",
        "prev": "https://localhost/WebService4/v5/internal/locations/marketplace?page[number]=0",
        "last": "https://localhost/WebService4/v5/internal/locations/marketplace?page[number]=12"
    }
}

Here is what i'm seeing in Visual Studio in the debugger. I'm not sure why it happens in that way as initial url it totally correct and doesn't have any encoding.

image

I pushed fix to use _baseUrl.ToString() so it won't do encoding there and port also won't be present. And added a couple of tests to validate it. The problem there is that in unit test it doesn't do that so it's hard to mimic that behavior and only way i was able to do it by specifying already encoded _baseUrl in UrlConstructionTests.SelfLinkNoEncodingBasedOnEncoded unit test.

Thanks!

Copy link
Owner

@joukevandermaas joukevandermaas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to me that the URI has whatever value was sent by the browser, so good to normalize it. I think the tests make sense. Thanks for addressing this right away!

@joukevandermaas joukevandermaas merged commit 126e952 into joukevandermaas:master Oct 23, 2019
@sergey-litvinov-work
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants