Skip to content

[BUG] The mime-detected suffix is ignored when saving an attached or inserted file #3701

Description

@VXNCXNX

Expected behaviour

When an attached file has no extension, or one that does not match its type, the saved copy should use the suffix QOwnNotes detected from the mime type.

Actual behaviour

That detected suffix is discarded, so the saved file keeps the suffix of the input path, or none at all.

Utils::Misc::findAvailableFileName() takes an overrideSuffix parameter (src/utils/misc.h:151) that its body never reads (src/utils/misc.cpp:2742):

const QString newSuffix = fileInfo.suffix();   // overrideSuffix unused

Both callers in src/entities/note.cpp pass a mime-detected suffix, at lines 6201 and 6300. The sibling makeFileNameRandom() has the same parameter and honours it.

Steps to reproduce

  1. Take a PNG file with its extension removed, named screenshot.
  2. Insert it with Insert attachment.
  3. It lands in the attachments folder still named screenshot, so it no longer opens in an image viewer on double click.

A JPEG named screenshot.jpeg is detected as jpg but keeps .jpeg.

Driving the real function with the same mime detection the callers use:

input 'screenshot'  mime=image/png  detected suffix='png'
   current : screenshot
   expected: screenshot.png

input 'screenshot.jpeg'  mime=image/jpeg  detected suffix='jpg'
   current : screenshot.jpeg
   expected: screenshot.jpg

Screenshots

Not applicable, this is a file naming issue.

Output from the debug section in the settings dialog

Expand

Not run from an installed instance. Found by reading the code, reproduced by building the unit test target from main against Qt 5.15.2 on Linux.

Relevant log output in the Log panel

Expand

Nothing is logged for this.

PR #3700 fixes this and adds a unit test.

Written with AI assistance (Claude Code). I built and ran the test target and produced the output above myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions