From 7edf477f64b65ffe22c966d6a8dcc3edd0fb6997 Mon Sep 17 00:00:00 2001 From: Jacobo de Vera Date: Mon, 27 Apr 2026 12:15:27 +0100 Subject: [PATCH] Fix --regex-pattern being ignored by the CLI The `--regex-pattern` argument was parsed by argparse but never forwarded into the `slugify()` call, so the option had no effect from the CLI. Fixes #175. --- CHANGELOG.md | 1 + slugify/__main__.py | 1 + test.py | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 537460e..44e0bb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## Unreleased +- Fix `--regex-pattern` being ignored by the CLI. - Support Python 3.14. - Drop support for Python 3.9 and lower. - Use tox for local test runs and in CI. 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..1c321d6 100644 --- a/test.py +++ b/test.py @@ -575,7 +575,8 @@ class TestCommandParams(unittest.TestCase): 'separator': '-', 'stopwords': None, 'lowercase': True, - 'replacements': None + 'replacements': None, + 'regex_pattern': None } def get_params_from_cli(self, *argv): @@ -623,6 +624,12 @@ def test_replacements_wrong(self): self.assertEqual(err.exception.code, 2) self.assertIn("Replacements must be of the form: ORIGINAL->REPLACED", cse.getvalue()) + def test_regex_pattern(self): + params = self.get_params_from_cli('--regex-pattern', '[^-a-z0-9_]+', '___This is a test___') + expected = self.make_params(text='___This is a test___', regex_pattern='[^-a-z0-9_]+') + self.assertParamsMatch(expected, params) + self.assertEqual(slugify(**params), '___this-is-a-test___') + def test_text_in_cli(self): params = self.get_params_from_cli('Cool Text') expected = self.make_params(text='Cool Text')