Fixed a bug where a string with multiple &'s wasn't getting escaped correctly... zero-width lookaheads to the rescue\!

This commit is contained in:
Anna 2010-07-13 09:53:21 -04:00
parent 94e28e6c7d
commit 59b4a0e543

View File

@ -470,16 +470,20 @@ class TweetBox(gtk.HBox):
else:
self.user_button.set_label(name + " (" + user.screen_name + ") ")
# and the text
### and the text
new_text = status.text
new_text = re.sub(r'&([^;]*?)( |$)', r'&\1\2', new_text)
new_text = re.sub(r'"([^;]*?)( |$)', r'"\1\2', new_text)
# Clean up odd characters in the text
new_text = re.sub(r'&(?=[^;]*?( |&|$))', r'&', new_text)
new_text = re.sub(r'"(?=[^;]*?( |"|$))', r'"', new_text)
if gtk.gtk_version[0] > 2 or (gtk.gtk_version[0] == 2 and gtk.gtk_version[1] >= 18):
# Make URLs into links
new_text = re.sub(r"(http://.*?)([^0-9a-zA-Z.~/_?=&-]|$)", r'<a href="\1">\1</a>\2', new_text)
new_text = re.sub(r"(http://.*?)(?=[^0-9a-zA-Z.~/_?=&;-]|$)", r'<a href="\1">\1</a>', new_text)
# Make @ or # refs into links, to be used internally
new_text = re.sub(r'@(.*?)([^0-9a-zA-Z_]|$)', self._make_user_link, new_text)
new_text = re.sub(r'#(.*?)([ ;,.:*]|$)', self._make_hashtag_link, new_text)
self.text.set_markup(new_text)
# If this is in reply to something, set appropriate label