punyencode only the host part of the URL. Fixes #7981

This commit is contained in:
Yann Leboulanger 2015-02-28 15:47:51 +01:00
parent b7c6d3e1b5
commit c2ac09cce2
2 changed files with 11 additions and 2 deletions

View File

@ -36,6 +36,7 @@ import os
import subprocess
import urllib
import urllib
from urlparse import urlparse
import webbrowser
import errno
import select
@ -137,6 +138,14 @@ def ascii_to_idn(host):
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

View File

@ -1218,8 +1218,8 @@ class ConversationTextview(GObject.GObject):
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