Repository: frappe/frappe

Issue:
bug: Strip EXIF data throws error when using SVG file
<!--
Welcome to the Frappe Framework issue tracker! Before creating an issue, please heed the following:

1. This tracker should only be used to report bugs and request features / enhancements to Frappe
    - For questions and general support, use https://stackoverflow.com/questions/tagged/frappe
    - For documentation issues, refer to https://frappeframework.com/docs/user/en or the developer cheetsheet https://github.com/frappe/frappe/wiki/Developer-Cheatsheet
2. Use the search function before creating a new issue. Duplicates will be closed and directed to
   the original discussion.
3. When making a bug report, make sure you provide all required information. The easier it is for
   maintainers to reproduce, the faster it'll be fixed.
4. If you think you know what the reason for the bug is, share it with us. Maybe put in a PR 😉
-->

## Description of the issue
Uploading a SVG file fails. 

## Context information (for bug reports)
Uploading a SVG file fails. It is uploads correctly when system setting is turned off.

**Output of `bench version`**
```
erpnext 13.1.0
frappe 13.1.2
```

## Steps to reproduce the issue

1.Upload a svg file from the File module (Or in any doctype)
2.It will throw an exception in the brower console.
Example file: https://logedosoft.com//files/intro-img.svg

### Observed result
Does nothing
### Expected result
It should upload the file
### Stacktrace / full error message


```
Traceback (most recent call last):
  File "/home/frappe-logedo/frappe-bench/apps/frappe/frappe/app.py", line 67, in application
    response = frappe.api.handle()
  File "/home/frappe-logedo/frappe-bench/apps/frappe/frappe/api.py", line 58, in handle
    return frappe.handler.handle()
  File "/home/frappe-logedo/frappe-bench/apps/frappe/frappe/handler.py", line 32, in handle
    data = execute_cmd(cmd)
  File "/home/frappe-logedo/frappe-bench/apps/frappe/frappe/handler.py", line 68, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe-logedo/frappe-bench/apps/frappe/frappe/__init__.py", line 1166, in call
    return fn(*args, **newargs)
  File "/home/frappe-logedo/frappe-bench/apps/frappe/frappe/handler.py", line 183, in upload_file
    ret.save(ignore_permissions=ignore_permissions)
  File "/home/frappe-logedo/frappe-bench/apps/frappe/frappe/model/document.py", line 284, in save
    return self._save(*args, **kwargs)
  File "/home/frappe-logedo/frappe-bench/apps/frappe/frappe/model/document.py", line 306, in _save
    self.insert()
  File "/home/frappe-logedo/frappe-bench/apps/frappe/frappe/model/document.py", line 230, in insert
    self.run_method("before_insert")
  File "/home/frappe-logedo/frappe-bench/apps/frappe/frappe/model/document.py", line 858, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/frappe-logedo/frappe-bench/apps/frappe/frappe/model/document.py", line 1147, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/frappe-logedo/frappe-bench/apps/frappe/frappe/model/document.py", line 1130, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/frappe-logedo/frappe-bench/apps/frappe/frappe/model/document.py", line 852, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/frappe-logedo/frappe-bench/apps/frappe/frappe/core/doctype/file/file.py", line 56, in before_insert
    self.save_file(content=self.content, decode=self.decode)
  File "/home/frappe-logedo/frappe-bench/apps/frappe/frappe/core/doctype/file/file.py", line 504, in save_file
    self.content = strip_exif_data(self.content, self.content_type)
  File "/home/frappe-logedo/frappe-bench/apps/frappe/frappe/utils/image.py", line 34, in strip_exif_data
    original_image = Image.open(io.BytesIO(content))
  File "/home/frappe-logedo/frappe-bench/env/lib/python3.8/site-packages/PIL/Image.py", line 2967, in open
    raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7ff8e7297ae0>
```

## Additional information

OS version / distribution, `Frappe` install method, etc.
Easy install on Ubuntu 20. (Thanks for that)


Discussion:
@TurkerTunali, Pillow doesn't support SVG files. The supported file formats are listed [here](https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html).
We should create an exception for svg.

Will create a PR for the same.

Resolving patch:
diff --git a/frappe/core/doctype/file/file.py b/frappe/core/doctype/file/file.py
--- a/frappe/core/doctype/file/file.py
+++ b/frappe/core/doctype/file/file.py
@@ -498,7 +498,7 @@ def save_file(self, content=None, decode=False, ignore_existing_file_check=False
 		self.file_size = self.check_max_file_size()
 
 		if (
-			self.content_type and "image" in self.content_type
+			self.content_type and self.content_type == "image/jpeg"
 			and frappe.get_system_settings("strip_exif_metadata_from_uploaded_images")
 		):
 			self.content = strip_exif_data(self.content, self.content_type)


Test patch: