Skip to content

Commit a80f95b

Browse files
humitosstsewd
andauthored
File Tree Diff: normalize ignore files (#11987)
Discussion #11977 (comment) --------- Co-authored-by: Santos Gallegos <[email protected]>
1 parent 1bcd53d commit a80f95b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

readthedocs/projects/forms.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,16 @@ def to_python(self, value):
672672
"""Convert a text area into a list of items (one per line)."""
673673
if not value:
674674
return []
675-
# Sanitize lines removing trailing spaces and skipping empty lines
676-
return [line.strip() for line in value.splitlines() if line.strip()]
675+
# Normalize paths and filter empty lines:
676+
# - remove trailing spaces
677+
# - skip empty lines
678+
# - remove starting `/`
679+
result = []
680+
for line in value.splitlines():
681+
normalized = line.strip().lstrip("/")
682+
if normalized:
683+
result.append(normalized)
684+
return result
677685

678686
def prepare_value(self, value):
679687
"""Convert a list of items into a text area (one per line)."""

readthedocs/rtd_tests/tests/test_project_forms.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@ def test_addonsconfig_form(self):
11811181
"doc_diff_enabled": False,
11821182
"filetreediff_enabled": True,
11831183
# Empty lines, lines with trailing spaces or lines full of spaces are ignored
1184-
"filetreediff_ignored_files": "user/index.html\n \n\n\n changelog.html \n",
1184+
"filetreediff_ignored_files": "user/index.html\n \n\n\n changelog.html \n/normalized.html",
11851185
"flyout_enabled": True,
11861186
"flyout_sorting": ADDONS_FLYOUT_SORTING_CALVER,
11871187
"flyout_sorting_latest_stable_at_beginning": True,
@@ -1206,7 +1206,11 @@ def test_addonsconfig_form(self):
12061206
self.assertEqual(self.project.addons.filetreediff_enabled, True)
12071207
self.assertEqual(
12081208
self.project.addons.filetreediff_ignored_files,
1209-
["user/index.html", "changelog.html"],
1209+
[
1210+
"user/index.html",
1211+
"changelog.html",
1212+
"normalized.html",
1213+
],
12101214
)
12111215
self.assertEqual(self.project.addons.notifications_enabled, True)
12121216
self.assertEqual(self.project.addons.notifications_show_on_latest, True)

0 commit comments

Comments
 (0)