Bug 481181

Summary: Can not select images using tag with leading/trailing whitespace in the tag name
Product: [Applications] kphotoalbum Reporter: rsquared42
Component: Annotation DialogAssignee: KPhotoAlbum Bugs <kpabugs>
Status: RESOLVED FIXED    
Severity: normal CC: johannes
Priority: NOR    
Version: GIT master   
Target Milestone: ---   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description rsquared42 2024-02-10 18:58:47 UTC
SUMMARY
My database had a tag with an unintended trailing space character.  Clicking on the tag showed zero thumbnails even though KPhotoalbum reported in the listview that the tag was assigned to hundreds of images.

This is reproducible with git master.

STEPS TO REPRODUCE
1. Open the demo database, click Events and then click on the "desktop" tag.  Four thumbnails are displayed.  
2. Select an image, open the annotation dialog, and rename the "desktop" tag to "desktop " (with a trailing space).
3. Click home, then Events.  Note that the trailing whitespace is not obvious in the list view.
4. Click on the "desktop " tag.  No thumbnails are displayed.

OBSERVED RESULT
The tag cannot be used to select images.

EXPECTED RESULT
The user should not be able to create a tag name with leading/trailing whitespace.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Ubuntu 22.04.3 LTS
KDE Frameworks Version: 5.104.0
Qt Version: 5.15.3

ADDITIONAL INFORMATION
Trailing whitespace is not obvious unless the tag name is selected in an edit control.

The same issue occurs with leading whitespace in the tag name, but it is more obvious if the tags are displayed in a list view because the tag name appears indented.
Comment 1 rsquared42 2024-02-10 19:22:57 UTC
A better expected result: an image should always be selectable using an assigned tag.

This is arguably a bug in the image selection logic, but is there a reason to allow leading/trailing whitespace in a tag name?
Comment 2 Johannes Zarl-Zierl 2024-02-11 15:11:29 UTC
The same behavior can also be triggered in the following ways:
- by annotating via the image viewer and adding a new tag using the "new" annotation mode ("F2", then "Ctrl-A", "Add tag")
- by renaming a tag group via Settings | Tag groups
Comment 3 Johannes Zarl-Zierl 2024-02-11 16:02:11 UTC
I didn't look into the reason why you can't navigate to a tag that begins or ends with a whitespace character, but you're right with your question - the bug is that these names can be entered at all.
Comment 4 Johannes Zarl-Zierl 2024-02-11 16:02:26 UTC
Git commit 7a1b41e5847efb2a9d9b5c8e34520a92ae726f1d by Johannes Zarl-Zierl.
Committed on 11/02/2024 at 15:57.
Pushed by johanneszarl into branch 'master'.

Prevent addition of tag names with leading/trailing whitespace

M  +19   -3    AnnotationDialog/ListSelect.cpp
M  +14   -7    Settings/TagGroupsPage.cpp
M  +2    -1    Viewer/SelectCategoryAndValue.cpp

https://invent.kde.org/graphics/kphotoalbum/-/commit/7a1b41e5847efb2a9d9b5c8e34520a92ae726f1d
Comment 5 Johannes Zarl-Zierl 2024-02-11 16:02:34 UTC
Git commit 7b97f61b160eda5aa1443bb22d4093cd0a7112e8 by Johannes Zarl-Zierl.
Committed on 11/02/2024 at 15:42.
Pushed by johanneszarl into branch 'master'.

Prevent introduction of trailing/leading whiteespace for tag names

This is only preventing unsanitized names to be entered into the
database, but does not prevent inconsistent UI.

M  +11   -9    DB/Category.cpp
M  +14   -3    DB/Category.h
M  +25   -21   DB/MemberMap.cpp
M  +5    -1    DB/MemberMap.h

https://invent.kde.org/graphics/kphotoalbum/-/commit/7b97f61b160eda5aa1443bb22d4093cd0a7112e8