From a779f5f477e8529bf48edcf9798cd164b8c16e26 Mon Sep 17 00:00:00 2001 From: Muneeb Sheikh Date: Sun, 11 Oct 2026 13:13:44 -0400 Subject: [PATCH] Preserve hash characters in Csv values --- decouple.py | 1 + tests/test_helper_csv.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/decouple.py b/decouple.py index 9873fc9..bf494c2 100644 --- a/decouple.py +++ b/decouple.py @@ -280,6 +280,7 @@ def __call__(self, value): transform = lambda s: self.cast(s.strip(self.strip)) splitter = shlex(value, posix=True) + splitter.commenters = '' splitter.whitespace = self.delimiter splitter.whitespace_split = True diff --git a/tests/test_helper_csv.py b/tests/test_helper_csv.py index c5db287..b127d87 100644 --- a/tests/test_helper_csv.py +++ b/tests/test_helper_csv.py @@ -34,3 +34,16 @@ def test_csv_quoted_parse(): def test_csv_none(): csv = Csv() assert [] == csv(None) + + +def test_csv_hash_characters_are_values(): + csv = Csv() + assert ['https://example.com/#section', 'next'] == \ + csv('https://example.com/#section,next') + assert ['#first', 'second#part', '#last'] == \ + csv('#first,second#part,#last') + + +def test_csv_hash_characters_with_custom_processing(): + csv = Csv(delimiter=';', post_process=tuple) + assert ('#first', 'second#part') == csv('#first;second#part')