From e0c40f36b7b7654e4b1ea0198f79d61a1d9c593e Mon Sep 17 00:00:00 2001 From: patchwright Date: Wed, 17 Jun 2026 23:11:05 +0200 Subject: [PATCH] fix: wire --regex-pattern through the CLI (#175) --- slugify/__main__.py | 1 + test.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/slugify/__main__.py b/slugify/__main__.py index 4e6b3d9..6e8109d 100644 --- a/slugify/__main__.py +++ b/slugify/__main__.py @@ -76,6 +76,7 @@ def slugify_params(args: argparse.Namespace) -> dict[str, Any]: save_order=args.save_order, separator=args.separator, stopwords=args.stopwords, + regex_pattern=args.regex_pattern, lowercase=args.lowercase, replacements=args.replacements, allow_unicode=args.allow_unicode diff --git a/test.py b/test.py index fcec4b6..b724894 100644 --- a/test.py +++ b/test.py @@ -574,6 +574,7 @@ class TestCommandParams(unittest.TestCase): 'save_order': False, 'separator': '-', 'stopwords': None, + 'regex_pattern': None, 'lowercase': True, 'replacements': None } @@ -645,6 +646,17 @@ def test_two_text_sources_fails(self): self.assertEqual(err.exception.code, 2) self.assertIn("Input strings and --stdin cannot work together", cse.getvalue()) + def test_regex_pattern(self): + # --regex-pattern must be passed through to slugify (issue #175). + params = self.get_params_from_cli('--regex-pattern', r'[^-a-z0-9_]+') + expected = self.make_params(regex_pattern=r'[^-a-z0-9_]+') + self.assertParamsMatch(expected, params) + + def test_regex_pattern_end_to_end(self): + # The example from issue #175: underscores must survive the custom pattern. + params = self.get_params_from_cli('--regex-pattern', r'[^-a-z0-9_]+', '___This is a test___') + self.assertEqual(slugify(**params), '___this-is-a-test___') + def test_multivalued_options_with_text(self): text = "the quick brown fox jumps over the lazy dog in a hurry" cli_args = "--stopwords the in a hurry -- {}".format(text).split()