Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Csv() on Backslash Escaped Strings #103

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions decouple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@henriquebastos I want to call your attention to this line -- it fixes the issue for me, but may introduce backwards incompatibilities. I'm not sure if you have other users relying on this behavior. I would be happy with just this change, but let me know if you want me to introduce it via a new optional command arg or other backwards compatible change.

splitter.whitespace = self.delimiter
splitter.whitespace_split = True

Expand Down
9 changes: 9 additions & 0 deletions tests/test_helper_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."