-
Notifications
You must be signed in to change notification settings - Fork 120
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
Support special characters in wiki page titles. #222
Conversation
Awesome, looks fantastic, but I would like to have a closer look before merging, will try to do this ASAP. |
Finally had some time to take a look, I really like the idea, but having thought about it a bit more I suggest we go a bit further, have a look at the following: class ResourceQueryFormatter(string.Formatter):
"""
Quotes query and memorizes all arguments, used during string formatting.
"""
def __init__(self):
self.used_kwargs = {}
self.unused_kwargs = {}
def check_unused_args(self, used_args, args, kwargs):
self.used_kwargs = {item: kwargs.pop(item) for item in used_args if item in kwargs}
self.unused_kwargs = kwargs
def format_field(self, value, format_spec):
return quote(super(ResourceQueryFormatter, self).format_field(value, format_spec).encode('utf-8'))
class ResourceQueryStr(str):
formatter = ResourceQueryFormatter()
def format(self, *args, **kwargs):
return self.formatter.format(self, *args, **kwargs) We can wrap all Also it should be pretty safe to just quote all the @rczajka Thoughts ? |
Looks like a good idea. One more thing I would probably do, just to keep the templating consistent, is then to clearly separate formatting the URLs from plain string manipulation, so change the remaining things like:
to things like:
But as long as it doesn't cough up on weird characters, that's fine by me. :) |
@rczajka Makes total sense. I think the url example is the only one that's not in the Do you have time to make the necessary changes ? If not that's also fine, we can merge this PR as is and I'll adjust the code a bit later. Just please remove the Thanks. |
Sure, I should have same time for that in the next week. |
Fantastic. Thanks! |
Done. |
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.
Beautiful, left a few comments, cosmetics mostly. We can merge afterwards.
Fantastic. Thanks! |
Redmine wiki pages titles can contain characters which need to be URL-encoded. This means the titles can't be pasted verbatim into the URL templates.
This change introduces a
string.Formatter
subclass whichurrlib.parse.quote
s the argument, and uses that to format the URLs where wiki page titles are used.