changeset b325ae9b2ad0 in /home/hg/repos/gajim
author: Yann Leboulanger asterix@lagaule.org branches: details:http://hg.gajim.org/gajim?cmd=changeset;node=b325ae9b2ad0 description: punyencode only the host part of the URL. Fixes #7981
diffstat:
src/common/helpers.py | 9 +++++++++ src/conversation_textview.py | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-)
diffs (40 lines):
diff -r fade7eb0d1d1 -r b325ae9b2ad0 src/common/helpers.py --- a/src/common/helpers.py Sat Feb 28 15:12:11 2015 +0100 +++ b/src/common/helpers.py Sat Feb 28 15:47:51 2015 +0100 @@ -36,6 +36,7 @@ import subprocess import urllib import urllib +from urlparse import urlparse import webbrowser import errno import select @@ -137,6 +138,14 @@ converted_labels.append(idna.ToUnicode(label)) return ".".join(converted_labels)
+def puny_encode_url(url): + _url = url + if '//' not in _url: + _url = '//' + _url + o = urlparse(_url) + p_loc = idn_to_ascii(o.netloc) + return url.replace(o.netloc, p_loc) + def parse_resource(resource): """ Perform stringprep on resource and return it diff -r fade7eb0d1d1 -r b325ae9b2ad0 src/conversation_textview.py --- a/src/conversation_textview.py Sat Feb 28 15:12:11 2015 +0100 +++ b/src/conversation_textview.py Sat Feb 28 15:47:51 2015 +0100 @@ -1218,8 +1218,8 @@ all_tags = [(ttt.lookup(t) if isinstance(t, str) else t) for t in all_tags] buffer_.insert_with_tags(end_iter, special_text, *all_tags) if 'url' in tags: - puny_text = puny_encode(special_text).decode('utf-8') - if not puny_text.endswith('-'): + puny_text = helpers.puny_encode_url(special_text) + if puny_text != special_text: puny_tags = [] if use_other_tags: puny_tags += other_tags