From 06479eda200e67bd90885022bce99aa74e5345d9 Mon Sep 17 00:00:00 2001 From: "Michael A. Smith" Date: Tue, 1 Dec 2020 20:14:48 -0500 Subject: [PATCH 1/2] Test Csv() on Backslash Escaped Strings A regular expression is often written with backslash escapes. This change introduces a test to check that the Csv helper does not strip backslashes from input strings. --- tests/test_helper_csv.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_helper_csv.py b/tests/test_helper_csv.py index 8d55a66..76397ac 100644 --- a/tests/test_helper_csv.py +++ b/tests/test_helper_csv.py @@ -29,3 +29,12 @@ def test_csv_quoted_parse(): assert ['foo', "'bar, baz'", "'qux"] == csv(''' foo ,"'bar, baz'", "'qux"''') assert ['foo', '"bar, baz"', '"qux'] == csv(""" foo ,'"bar, baz"', '"qux'""") + + +def test_csv_backslash(): + csv = Csv() + + raw = r'first,^https://\w+\.example\.com$,third' + + assert ['first', '^https://\\w+\\.example\\.com$', 'third'] == \ + csv(raw), "Csv helper removed backslashes." From c457e3f343594a94b272c2deffd85b8037696d2f Mon Sep 17 00:00:00 2001 From: "Michael A. Smith" Date: Tue, 1 Dec 2020 20:30:39 -0500 Subject: [PATCH 2/2] Do not drop backslashes --- decouple.py | 1 + 1 file changed, 1 insertion(+) diff --git a/decouple.py b/decouple.py index 0788928..226fcc9 100644 --- a/decouple.py +++ b/decouple.py @@ -228,6 +228,7 @@ def __call__(self, value): transform = lambda s: self.cast(s.strip(self.strip)) splitter = shlex(value, posix=True) + splitter.escape = '' # Do not escape backslashes splitter.whitespace = self.delimiter splitter.whitespace_split = True