Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

force replace_by to be unicode in remove_escape_chars, added tests

Ismael Carnales1b3d40e63902
diff --git a/scrapy/tests/test_utils_markup.py b/scrapy/tests/test_utils_markup.py
index a8579c818..06df84a2b 100644
--- a/scrapy/tests/test_utils_markup.py
+++ b/scrapy/tests/test_utils_markup.py
@@ -112,6 +112,7 @@ class UtilsMarkupTest(unittest.TestCase):
self.assertEqual(remove_escape_chars(u'escape\n\n'), u'escape')
self.assertEqual(remove_escape_chars(u'escape\n', which_ones=('\t',)), u'escape\n')
self.assertEqual(remove_escape_chars(u'escape\tchars\n', which_ones=('\t')), 'escapechars\n')
+ self.assertEqual(remove_escape_chars(u'escape\tchars\n', replace_by=' '), 'escape chars ')
def test_unquote_markup(self):
sample_txt1 = u"""<node1>hi, this is sample text with entities: &amp; &copy;
diff --git a/scrapy/utils/markup.py b/scrapy/utils/markup.py
index 09ef64192..9a9786072 100644
--- a/scrapy/utils/markup.py
+++ b/scrapy/utils/markup.py
@@ -105,14 +105,14 @@ def remove_tags_with_content(text, which_ones=()):
return text
-def remove_escape_chars(text, which_ones=('\n','\t','\r'), replace_str=u''):
+def remove_escape_chars(text, which_ones=('\n','\t','\r'), replace_by=u''):
""" Remove escape chars. Default : \\n, \\t, \\r
which_ones -- is a tuple of which escape chars we want to remove.
By default removes \n, \t, \r.
"""
for ec in which_ones:
- text = text.replace(ec, replace_str)
+ text = text.replace(ec, str_to_unicode(replace_by))
return str_to_unicode(text)
def unquote_markup(text, keep=(), remove_illegal=True):