From bb33663472497a70314af0dafe98527afb4fd01a Mon Sep 17 00:00:00 2001 From: Matt Jeffery Date: Fri, 1 Mar 2013 20:14:18 +0000 Subject: [PATCH] replace '&' with & when it is not in a character entity (approximation) --- pylast.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pylast.py b/pylast.py index c73f9e0..b3f9572 100644 --- a/pylast.py +++ b/pylast.py @@ -33,6 +33,7 @@ import tempfile import sys import collections import warnings +import re def _deprecation_warning(message): warnings.warn(message, DeprecationWarning) @@ -847,6 +848,10 @@ class _Request(object): except Exception as e: raise MalformedResponseError(self.network, e) + # Pretty decent catch for invalid & characters - which last.fm + # seems to generate for some artist eg. "K'nann" + response_text = re.sub("&(?![^\W]+;)", "&", response_text) + self._check_response_for_errors(response_text) return response_text