diff --git a/README.md b/README.md index edccd04..726c833 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/e2e/e2e_namespace_file.py b/e2e/e2e_namespace_file.py index 5c94a20..7e3d368 100644 --- a/e2e/e2e_namespace_file.py +++ b/e2e/e2e_namespace_file.py @@ -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() @@ -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() @@ -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") diff --git a/truewiki/namespaces/file/namespace.py b/truewiki/namespaces/file/namespace.py index c559514..e81313d 100644 --- a/truewiki/namespaces/file/namespace.py +++ b/truewiki/namespaces/file/namespace.py @@ -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 @@ -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"):