Skip to content

File Tree Diff: normalize ignore files #11987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()]
# Sanitize 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