Skip to content

Commit e4a4e35

Browse files
committed
added configurable variables to docs and apps settings
1 parent a68a611 commit e4a4e35

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

docs/ref/settings.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,26 @@ Default: ``False``
2525
Wheter to show or hide breadcrumbs at site's root.
2626

2727

28+
DYNAMIC_BREADCRUMBS_PATH_ONLY_ALPHANUMERIC
29+
------------------------------------------
30+
31+
Default: ``True``
32+
33+
Only allows alphanumeric characters in breadcrumb item names. If
34+
someone contains non-alphanumeric values it will show an empty string.
35+
36+
37+
DYNAMIC_BREADCRUMBS_PATH_MAX_DEPTH
38+
----------------------------------
39+
40+
Default: ``5``
41+
42+
The maximum number of breadcrumb items to show
43+
44+
45+
DYNAMIC_BREADCRUMBS_PATH_MAX_COMPONENT_LENGTH
46+
---------------------------------------------
47+
48+
Default: ``50``
49+
50+
Each path component's maximum length.

dynamic_breadcrumbs/app_settings.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
SHOW_AT_BASE_PATH = getattr(
77
settings, "DYNAMIC_BREADCRUMBS_SHOW_AT_BASE_PATH", False
88
)
9-
SHOW_VERBOSE_NAME = getattr(
10-
settings, "DYNAMIC_BREADCRUMBS_SHOW_VERBOSE_NAME", True
11-
)
129

1310
PATH_ALPHANUMERIC = getattr(
1411
settings, "DYNAMIC_BREADCRUMBS_PATH_ONLY_ALPHANUMERIC", True
1512
)
13+
PATH_MAX_DEPTH = getattr(
14+
settings, "DYNAMIC_BREADCRUMBS_PATH_MAX_DEPTH", 5
15+
)
16+
PATH_MAX_COMPONENT_LENGTH = getattr(
17+
settings, "DYNAMIC_BREADCRUMBS_PATH_MAX_COMPONENT_LENGTH", 50
18+
)

dynamic_breadcrumbs/utils.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212

1313
logger = logging.getLogger(__name__)
1414

15-
#ALLOWED_BASE_URLS = [settings.ALLOWED_HOSTS] # Add your allowed base URLs here
16-
MAX_PATH_DEPTH = 5
17-
MAX_PATH_COMPONENT_LENGTH = 50
18-
1915

2016
def sanitize_url(url):
2117
"""Sanitize the URL to prevent malicious content."""
@@ -33,21 +29,21 @@ def validate_path(path):
3329
logger.warning("Invalid path type provided: %s", type(path))
3430
return ""
3531

36-
if app_settings.PATH_ONLY_ALPHANUMERIC:
32+
if app_settings.PATH_ALPHANUMERIC:
3733
# Ensure the path contains only alphanumeric characters, dashes, underscores, and slashes
3834
if not re.match(r'^[a-zA-Z0-9_\-/]*$', path):
3935
logger.warning("Invalid path provided: %s", path)
4036
return ""
4137

4238
components = path.split('/')
4339
# Check path depth
44-
if len(components) > MAX_PATH_DEPTH:
40+
if len(components) > app_settings.PATH_MAX_DEPTH:
4541
logger.warning("Path depth exceeded for: %s", path)
4642
return ""
4743

4844
# Check each path component's length
4945
for component in components:
50-
if len(component) > MAX_PATH_COMPONENT_LENGTH:
46+
if len(component) > app_settings.PATH_MAX_COMPONENT_LENGTH:
5147
logger.warning("Path component length exceeded in: %s", path)
5248
return ""
5349

0 commit comments

Comments
 (0)