summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVal Neekman (AvidCoder) <un33kvu@gmail.com>2022-02-16 17:46:24 -0500
committerVal Neekman (AvidCoder) <un33kvu@gmail.com>2022-02-16 17:46:24 -0500
commitc096bcdd76b0ef216716eccef5b19839266e1372 (patch)
tree888711232e1b5c92f6757c38ed963dbf2a8a5849
parent86d76eead5430ec9b36b178dc0f3cb9b8ec20127 (diff)
downloadpython-slugify-c096bcdd76b0ef216716eccef5b19839266e1372.tar.gz
regex: allow=>disallowv6.0.1
-rw-r--r--.github/workflows/ci.yml1
-rw-r--r--CHANGELOG.md5
-rw-r--r--README.md2
-rw-r--r--slugify/__main__.py2
-rw-r--r--slugify/__version__.py2
-rw-r--r--slugify/slugify.py15
6 files changed, 15 insertions, 12 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d4998a5..4148354 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -6,6 +6,7 @@ on:
push:
branches:
- ci
+ - staging
jobs:
build:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8053b87..95ad243 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 6.0.1
+
+- Rework regex_pattern to mean the opposite (disallowed chars instead of allowed)
+- Thanks to @yyyyyyyan for the initial PR followed by the final PR by @mrezzamoradi
+
## 6.0.0
- Enable github action
diff --git a/README.md b/README.md
index af10080..11e20da 100644
--- a/README.md
+++ b/README.md
@@ -55,7 +55,7 @@ def slugify(
:param save_order (bool): if parameter is True and max_length > 0 return whole words in the initial order
:param separator (str): separator between words
:param stopwords (iterable): words to discount
- :param regex_pattern (str): regex pattern for allowed characters
+ :param regex_pattern (str): regex pattern for disallowed characters
:param lowercase (bool): activate case sensitivity by setting it to False
:param replacements (iterable): list of replacement rules e.g. [['|', 'or'], ['%', 'percent']]
:return (str): slugify text
diff --git a/slugify/__main__.py b/slugify/__main__.py
index ffdfd5f..5a888fe 100644
--- a/slugify/__main__.py
+++ b/slugify/__main__.py
@@ -31,7 +31,7 @@ def parse_args(argv):
parser.add_argument("--stopwords", nargs='+',
help="Words to discount")
parser.add_argument("--regex-pattern",
- help="Python regex pattern for allowed characters")
+ help="Python regex pattern for disallowed characters")
parser.add_argument("--no-lowercase", action='store_false', dest='lowercase', default=True,
help="Activate case sensitivity")
parser.add_argument("--replacements", nargs='+',
diff --git a/slugify/__version__.py b/slugify/__version__.py
index 4e5471b..1eedf44 100644
--- a/slugify/__version__.py
+++ b/slugify/__version__.py
@@ -5,4 +5,4 @@ __description__ = 'A Python slugify application that also handles Unicode'
__url__ = 'https://github.com/un33k/python-slugify'
__license__ = 'MIT'
__copyright__ = 'Copyright 2022 Val Neekman @ Neekware Inc.'
-__version__ = '6.0.0'
+__version__ = '6.0.1'
diff --git a/slugify/slugify.py b/slugify/slugify.py
index f38df10..190ea92 100644
--- a/slugify/slugify.py
+++ b/slugify/slugify.py
@@ -1,6 +1,7 @@
import re
-import unicodedata
import sys
+import typing
+import unicodedata
from html.entities import name2codepoint
try:
@@ -15,8 +16,7 @@ CHAR_ENTITY_PATTERN = re.compile(r'&(%s);' % '|'.join(name2codepoint))
DECIMAL_PATTERN = re.compile(r'&#(\d+);')
HEX_PATTERN = re.compile(r'&#x([\da-fA-F]+);')
QUOTE_PATTERN = re.compile(r'[\']+')
-ALLOWED_CHARS_PATTERN = re.compile(r'[^-a-z0-9]+')
-ALLOWED_CHARS_PATTERN_WITH_UPPERCASE = re.compile(r'[^-a-zA-Z0-9]+')
+DISALLOWED_CHARS_PATTERN = re.compile(r'[^-a-zA-Z0-9]+')
DUPLICATE_DASH_PATTERN = re.compile(r'-{2,}')
NUMBERS_PATTERN = re.compile(r'(?<=\d),(?=\d)')
DEFAULT_SEPARATOR = '-'
@@ -66,7 +66,7 @@ def smart_truncate(string, max_length=0, word_boundary=False, separator=' ', sav
def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, word_boundary=False,
separator=DEFAULT_SEPARATOR, save_order=False, stopwords=(), regex_pattern=None, lowercase=True,
- replacements=()):
+ replacements: typing.Iterable[typing.Iterable[str]] = ()):
"""
Make a slug from the given text.
:param text (str): initial text
@@ -78,7 +78,7 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w
:param save_order (bool): if parameter is True and max_length > 0 return whole words in the initial order
:param separator (str): separator between words
:param stopwords (iterable): words to discount
- :param regex_pattern (str): regex pattern for allowed characters
+ :param regex_pattern (str): regex pattern for disallowed characters
:param lowercase (bool): activate case sensitivity by setting it to False
:param replacements (iterable): list of replacement rules e.g. [['|', 'or'], ['%', 'percent']]
:return (str):
@@ -137,10 +137,7 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w
text = NUMBERS_PATTERN.sub('', text)
# replace all other unwanted characters
- if lowercase:
- pattern = regex_pattern or ALLOWED_CHARS_PATTERN
- else:
- pattern = regex_pattern or ALLOWED_CHARS_PATTERN_WITH_UPPERCASE
+ pattern = regex_pattern or DISALLOWED_CHARS_PATTERN
text = re.sub(pattern, DEFAULT_SEPARATOR, text)
# remove redundant