Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Parameters like `thumb`, `frame`, `left`, `link=` etc are all supported.

`[[:File:en/MyFile.png]]` adds a link to the file.

Files have to be either PNG (with `.png` extension), GIF (with `.gif` extension), or JPEG (with `.jpeg` extension).
Files have to be either PNG (with `.png` extension), GIF (with `.gif` extension), or JPEG (with `.jpeg` or `.jpg` extension).
No other formats are supported, and you have to upload the correct type for the given extension.

#### Folder
Expand Down
25 changes: 23 additions & 2 deletions e2e/e2e_namespace_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_file_view_bad_extension(page: Page):
expect(
page.locator(
'text=Page name "File/en/Test.image" in the File namespace should'
' end with either ".png", ".gif", or ".jpeg".'
' end with either ".png", ".gif", ".jpeg", or ".jpg".'
)
).to_be_visible()

Expand Down Expand Up @@ -192,7 +192,7 @@ def test_file_upload_wrong_jpeg(page: Page, login):
page.wait_for_url("http://localhost:8080/edit/File/en/Test.png")

expect(
page.locator('text=Page name "File/en/Test.png" should end with ".jpeg" if uploading a JPEG.')
page.locator('text=Page name "File/en/Test.png" should end with ".jpeg" or ".jpg" if uploading a JPEG.')
).to_be_visible()


Expand Down Expand Up @@ -288,6 +288,27 @@ def test_file_upload_jpeg(page: Page, login):
expect(page.locator("text=Filesize: 3.05 KiB")).to_be_visible()


def test_file_upload_jpg(page: Page, login):
"""Check that we can upload JPEG images with a .jpg extension."""
page.goto("http://localhost:8080/File/en/Test.jpg")

create = page.locator("text=Create Page")
expect(create).to_be_visible()
with page.expect_navigation():
create.click()
page.wait_for_url("http://localhost:8080/edit/File/en/Test.jpg")

page.locator("[name=file]").set_input_files("e2e/test.jpeg")
page.locator("[name=content]").fill("My Fourth Upload")
with page.expect_navigation():
page.locator("[name=save]").click()
page.wait_for_url("http://localhost:8080/File/en/Test.jpg")

expect(page).to_have_title("Unnamed | Test.jpg")
expect(page.locator("text=My Fourth Upload")).to_be_visible()
expect(page.locator("text=Filesize: 3.05 KiB")).to_be_visible()


def test_file_cannot_rename(page: Page, login):
"""Check if we cannot rename a file that is being used by another page."""
page.goto("http://localhost:8080/File/en/Test.png")
Expand Down
11 changes: 7 additions & 4 deletions truewiki/namespaces/file/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ def page_is_valid(cls, page: str, is_new_page: bool) -> Optional[str]:
return f'Page name "{page}" is in language "{spage[1]}" that does not exist.'

if not cls._is_language_root(page) and not cls._is_root_of_folder(page):
if not page.endswith((".png", ".jpeg", ".gif")):
return f'Page name "{page}" in the File namespace should end with either ".png", ".gif", or ".jpeg".'
if not page.endswith((".png", ".jpeg", ".jpg", ".gif")):
return (
f'Page name "{page}" in the File namespace should end with either'
' ".png", ".gif", ".jpeg", or ".jpg".'
)

return None

Expand Down Expand Up @@ -215,8 +218,8 @@ def edit_callback(old_page: str, new_page: str, payload, execute: bool = False):
if not data.startswith(b"\xff\xd8") or not data.endswith(b"\xff\xd9"):
return f'Uploaded file "{payload["file"].filename}" is not a valid JPEG image.'

if not new_page.endswith(".jpeg"):
return f'Page name "{new_page}" should end with ".jpeg" if uploading a JPEG.'
if not new_page.endswith((".jpeg", ".jpg")):
return f'Page name "{new_page}" should end with ".jpeg" or ".jpg" if uploading a JPEG.'
elif payload["file"].content_type == "image/gif":
# See https://en.wikipedia.org/wiki/GIF#File_format
if not data.startswith(b"GIF87a") and not data.startswith(b"GIF89a"):
Expand Down