playwright
playwright copied to clipboard
[BUG] `determineFileExtension` / `toMatchSnapshot` does not detect JPEG in EXIF format
System info
- Playwright Version: [v1.XX]
- Operating System: [All, Windows 11, Ubuntu 20, macOS 13.2, etc.]
- Browser: [All, Chromium, Firefox, WebKit]
- Other info:
Source code
Relevant code:
https://github.com/microsoft/playwright/blob/2d5488d8e31dcd3f04dbefc9e7d4f1c4b25fc8bc/packages/playwright/src/matchers/toMatchSnapshot.ts#L470-L471
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01, 0x01 is just one of the possible file signatures for JPEG.
See https://en.wikipedia.org/wiki/List_of_file_signatures for a list of more.
In my case, the sequence is ff d8 ff e1 00 bc 45 78 69 66 00 00 49 instead.
Because determineFileExtension does not recognize this byte sequence, the jpeg is falsely saved with a .dat extension.
A workaround is to provide a custom snapshot name.
Steps
example image:
Run expect( /* get above jpeg as buffer here */ ).toMatchSnapshot()
Expected
File should be saved as .jpg
Actual
File is saved as .dat because of unrecognized format
Do you want to send a PR?
Hey @pavelfeldman, I have a PR to fix this issue: https://github.com/microsoft/playwright/pull/29208, would be great if you could take a look, thanks!
Fixed in https://github.com/microsoft/playwright/pull/29208.