Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions e2e/e2e_namespace_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,16 @@
expect(
page.locator('text=Page name "Folder/Page2/Main Page" is in namespace "Page2" that does not exist.')
).to_be_visible()


def test_folder_category_no_crash(page: Page):
"""Check that accessing Folder/Category doesn't cause an IndexError crash."""
page.goto("http://localhost:8080/Folder/Category")

# Before the fix, this would crash with an IndexError when page_get_language

Check warning on line 91 in e2e/e2e_namespace_folder.py

View workflow job for this annotation

GitHub Actions / Testing / Flake8 / Flake8

trailing whitespace
# tried to access page.split("/")[2] on ["Folder", "Category"].
# After the fix, it should show an appropriate error message.
# Since Category is a namespace, it should show the namespace error message.
expect(
page.locator('text=Page name "Folder/Category/Main Page" is in namespace "Category" that does not exist.')
).to_be_visible()
5 changes: 4 additions & 1 deletion truewiki/namespaces/folder/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ def page_get_language(cls, page: str) -> Optional[str]:
if cls._is_namespace_root(page):
return None

return page.split("/")[2]
spage = page.split("/")
if len(spage) < 3:
return None
return spage[2]

@staticmethod
def get_used_on_pages(page: str) -> list:
Expand Down
Loading