getkirby / kirby

Kirby's core application folder
https://getkirby.com
Other
1.31k stars 168 forks source link

[Panel] Image could not be replaced by svg #15

Closed jenstornell closed 6 years ago

jenstornell commented 6 years ago

When trying to replace an image it says "arrow-left.svg The mime type of the new file does not match the old one". Both files are svg and I can upload my file, but not replace over another svg file.

Do they really need to be the same mime type to be replaced? If yes, why?

bastianallgeier commented 6 years ago

There's probably an issue with the mime type detection here.

Checking for the same mime type seemed to be the most reasonable way of validation so far. We also have this for Kirby 2. What would be the option to replace files otherwise? Can they simple be replaced with anything else and they would just inherit the name and the meta content? If yes, this would have a lot of logical steps involved.

jenstornell commented 6 years ago

I used the arrow-left.svg from the starterkit and it looks like this:

<svg viewBox="0 0 24 12"><path d="M1.94 6a28.38 28.38 0 0 0 8-4.47L8.71 5h12.23v2H8.71L10 10.47A28.4 28.4 0 0 0 1.94 6z"/></svg>

I'm not an SVG expert but it looks like something is missing there? If so, maybe it's working as expected.

I'm not sure if it should be replaced by anything. A SVG file, replaced by a SVG file should however work.

I would probably just see if the extension was the same on both files, but maybe it's not that hacker proof?

bastianallgeier commented 6 years ago

It's a pretty radically optimized SVG. I guess we need to adjust our mime type detector for such SVGs.

distantnative commented 6 years ago

Started to narrow it down: BlueprintFileSection.php at line 57 fails:

new MimeType($rules['mime']))->has($image->mime())

Testing $image->mime() directly with the svg file, returns image/svg+xml. However, when uploading the SVG at that line we only get text/plain. And as filename phprDly2R with no extension at all.

bastianallgeier commented 6 years ago