Skip to content

Commit

Permalink
File Tree Diff: normalize ignore files (#11987)
Browse files Browse the repository at this point in the history
Discussion

#11977 (comment)

---------

Co-authored-by: Santos Gallegos <stsewd@proton.me>
  • Loading branch information
humitos and stsewd authored Feb 11, 2025
1 parent 1bcd53d commit a80f95b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 10 additions & 2 deletions readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,16 @@ def to_python(self, value):
"""Convert a text area into a list of items (one per line)."""
if not value:
return []
# Sanitize lines removing trailing spaces and skipping empty lines
return [line.strip() for line in value.splitlines() if line.strip()]
# Normalize paths and filter empty lines:
# - remove trailing spaces
# - skip empty lines
# - remove starting `/`
result = []
for line in value.splitlines():
normalized = line.strip().lstrip("/")
if normalized:
result.append(normalized)
return result

def prepare_value(self, value):
"""Convert a list of items into a text area (one per line)."""
Expand Down
8 changes: 6 additions & 2 deletions readthedocs/rtd_tests/tests/test_project_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ def test_addonsconfig_form(self):
"doc_diff_enabled": False,
"filetreediff_enabled": True,
# Empty lines, lines with trailing spaces or lines full of spaces are ignored
"filetreediff_ignored_files": "user/index.html\n \n\n\n changelog.html \n",
"filetreediff_ignored_files": "user/index.html\n \n\n\n changelog.html \n/normalized.html",
"flyout_enabled": True,
"flyout_sorting": ADDONS_FLYOUT_SORTING_CALVER,
"flyout_sorting_latest_stable_at_beginning": True,
Expand All @@ -1206,7 +1206,11 @@ def test_addonsconfig_form(self):
self.assertEqual(self.project.addons.filetreediff_enabled, True)
self.assertEqual(
self.project.addons.filetreediff_ignored_files,
["user/index.html", "changelog.html"],
[
"user/index.html",
"changelog.html",
"normalized.html",
],
)
self.assertEqual(self.project.addons.notifications_enabled, True)
self.assertEqual(self.project.addons.notifications_show_on_latest, True)
Expand Down

0 comments on commit a80f95b

Please sign in to comment.