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

Url parameters of type DateTime[Offset] should be urlencoded #327

Open
rodro75 opened this issue Feb 5, 2020 · 0 comments
Open

Url parameters of type DateTime[Offset] should be urlencoded #327

rodro75 opened this issue Feb 5, 2020 · 0 comments

Comments

@rodro75
Copy link
Contributor

rodro75 commented Feb 5, 2020

This may be a corner case, but if you define a controller method like this one:

[Route("foo")]
public async Task FooAsync(DateTimeOffset? timestamp = null)

the typescript code generated by the built-in $Url directive is:

`/foo?timestamp=${timestamp}`

but it should really be:

`/foo?timestamp=${encodeURIComponent(String(timestamp))}`

because dates may contain the "+" character for the timezone part when serialized.

Now, because in urls the "+" character is historically interpreted as a space, when timestamps like "2020-02-04T19:25:00+01:00" or "Tue Feb 4 2020 19:25:00 GMT+0100" are sent back to the server ASP.Net would decode them as "2020-02-04T19:25:00 01:00" or "Tue Feb 4 2020 19:25:00 GMT 0100". In both cases the Json deserializer won't recognize the string as a valid date, so the WebApi infrastructure will just pass null into the parameter (or send back a 404 in case the parameter didn't have a default value).

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

No branches or pull requests

1 participant