-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
Plus sign in timezone designator #1787
base: dev
Are you sure you want to change the base?
Plus sign in timezone designator #1787
Conversation
Test timezone with positive UTC offset
From a quick check, I don't think a space instead of a + is valid ISO8601, so I'd rather not merge this. The SO issue you link to seems to be related to URL encoding. Arguments should be URL encoded. |
No problem, and thanks for checking, I should have discussed this first. Indeed this is a URL encoding issue, and a suggested fix that deviates from the ISO8601 specs. Sometimes it pays to be flexible, for example, Django accepting a minus sign in ISO8601 durations, but this is probably not the right hammer here. For the record, I ran into this when validating the url search parameter |
Does this fail validation? It doesn't have a space. |
It fails validation only because the + in the url search parameter is replaced by a space before it reaches Marshmallow validation. In the test, I mimicked this behaviour by using Here's a simple example (which I probably should have used to open up an issue instead of immediately making a PR):
|
If you confirm the issue, should I take it up elsewhere (any hint as to where?), or would you consider a (this) fix in Marshmallow? |
Should I open an Issue instead? Or can I otherwise provide more clarity on this problem? |
The problem is clear. I understand the use case. We could argue that serialization should be strict by default. But I think there are other places in the code where it is more permissive by default, so this argument is week. I'd like to move to standard lib Ultimately, parameters should be URL-encoded. The user is free to customize the field to fix the encoding so that the fix will still stand when/if we use I'm not a regex expert but it should be possible to do the space -> plus replacement in a safe way before feeding the input to the deserialization function. |
Good idea to rely on the standard library. Afaik the parameter is actually correctly url-encoded when it reaches validation, in accordance with RFC 1866 section 8.2.1 subparagraph 1. The space -> plus replacement you mention is precisely what I did to overcome this issue last year here:
This works because there should be no space in a valid ISO 8601 timestamp. However, the RFC 3339 profile does allow a space to be used instead of the T, as does datetime.fromisoformat(). To avoid replacing the wrong space, we could use the following regex instead:
Whether this is needed depends on whether Marshmallow uses The substitution could happen in Of course, I'd be happy to amend my PR. |
This PR adds some tests for a timezone with positive UTC offset. It also makes a real code change, by relaxing the ISO datetime regex to allow a space in addition to the + or - already allowed to specify UTC offset.
This resolves an issue where an ISO datetime passed as
application/x-www-form-urlencoded
has its + replaced by a space (see this SO issue).That is:
2018-03-03T00:00:00.000000+00:50
sent as a url parameter can be received as2018-03-03T00:00:00.000000 00:50
.