Bug 483320 - Empty <title> breaks other placeholders nearby
Summary: Empty <title> breaks other placeholders nearby
Status: RESOLVED FIXED
Alias: None
Product: Spectacle
Classification: Applications
Component: General (show other bugs)
Version: 24.02.0
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Noah Davis
URL:
Keywords:
: 486542 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-03-12 08:06 UTC by 0BADC0DE
Modified: 2024-05-16 13:40 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In: 24.05
Sentry Crash Report:


Attachments
Comparison between code and application text (330.83 KB, image/png)
2024-03-12 09:16 UTC, 0BADC0DE
Details
Screenshot of Spetacle configuration with template and preview (345.29 KB, image/png)
2024-03-15 08:28 UTC, 0BADC0DE
Details
While using "Save as". Suggested name has an unhandled partial placeholder. (167.95 KB, image/png)
2024-03-15 08:30 UTC, 0BADC0DE
Details

Note You need to log in before you can comment on or make changes to this bug.
Description 0BADC0DE 2024-03-12 08:06:09 UTC
SUMMARY
Spectacle doesn't interpret the "<ss>" (seconds?) placeholder put in the filename template setup in Image saving configuration set.


STEPS TO REPRODUCE
1.  Open Spectacle
2. Go to "Configure" -> "Image Saving"
3.  Verify that the "Filename" filed contains the "<ss>" placeholder (is should be there by default)
4. Take a screenshot
5. Open the saving folder

OBSERVED RESULT
The saved screenshot has "<ss" (without the ">") in the name instead of the number of seconds.

EXPECTED RESULT
The saved screenshot follows the filename template defined in the configuration.

SOFTWARE/OS VERSIONS
Kernel Version : 6.7.9.zen1-1
Plasma Version : 6.0.1-3
KDE Version : 24.02.0-1
Frameworks Version : 5.115.0-1
Qt5 Version : 5.15.12+kde+r10-1
Qt6 Version : 6.6.2-4
Wayland Version : 1.22.0-1
XOrg/Wayland Version : 23.2.4-2
Mesa Version : 1:24.0.2-2
LibVA Version : 2.20.0-1
VDPAU Version : 1.5-2


ADDITIONAL INFORMATION
This bug makes it impossible to take more than 1 screenshot per minute by overwriting all screenshots taken in the same minute. This is why I labelled it as major: I discovered this when I needed the screenshots!
Comment 1 0BADC0DE 2024-03-12 08:08:42 UTC
Not really. Please move this to "Normal": screenshot names are appended a numeric "discriminator".
Comment 2 0BADC0DE 2024-03-12 08:09:12 UTC
Fun fact: you cannot take a screenshot of spectacle.
I think this is NOT a bug.
Comment 3 0BADC0DE 2024-03-12 09:15:17 UTC
I see a lot of confusion in kconf_update/spectacle-24.02.0-change_placeholder_format.cpp and src/ExportManager.cpp files with "hh" and "HH". See attachment.
Are those string in the const ValueMap oldNewMap to be passwd to strftime?
Comment 4 0BADC0DE 2024-03-12 09:16:33 UTC
Created attachment 167021 [details]
Comparison between code and application text

I see also what the actual is...
Comment 5 0BADC0DE 2024-03-12 09:17:45 UTC
I can now see that it's is the last placeholder to create the problem.
I have added now "<t>" and the seconds pop up correctly in the filename.
Now I get a trailing "<t" before the ".png".
Comment 6 0BADC0DE 2024-03-12 09:21:48 UTC
SUMMARY
Spectacle doesn't interpret correctly the last placeholder put in the filename template setup in Image saving configuration set.
For example, "<ss>" is read or interpreted as "<ss" and thus not matched into the oldNewMap in kconf_update/spectacle-24.02.0-change_placeholder_format.cpp source file.
Comment 7 Noah Davis 2024-03-13 15:57:11 UTC
(In reply to 0BADC0DE from comment #3)
> I see a lot of confusion in
> kconf_update/spectacle-24.02.0-change_placeholder_format.cpp and
> src/ExportManager.cpp files with "hh" and "HH". See attachment.
> Are those string in the const ValueMap oldNewMap to be passwd to strftime?

spectacle-24.02.0-change_placeholder_format.cpp is a configuration migration script. It should have no impact on how the program actually works. Only ExportManager.cpp determines the behavior.
Comment 8 Noah Davis 2024-03-13 16:03:37 UTC
(In reply to 0BADC0DE from comment #2)
> Fun fact: you cannot take a screenshot of spectacle.
> I think this is NOT a bug.

Open spectacle from the command line with the `-i` or `--new-instance` option
Comment 9 Noah Davis 2024-03-13 16:05:46 UTC
Unfortunately, I cannot reproduce this bug.
Comment 10 0BADC0DE 2024-03-14 07:13:32 UTC
(In reply to Noah Davis from comment #9)
> Unfortunately, I cannot reproduce this bug.

What is your last placeholder in your configuration?
If I have <ss> or <t> I get the weird behavior. I haven't checked all other placeholders, though.
Comment 11 0BADC0DE 2024-03-14 07:14:32 UTC
(In reply to Noah Davis from comment #8)
> (In reply to 0BADC0DE from comment #2)
> > Fun fact: you cannot take a screenshot of spectacle.
> > I think this is NOT a bug.
> 
> Open spectacle from the command line with the `-i` or `--new-instance` option

(In reply to Noah Davis from comment #7)
> (In reply to 0BADC0DE from comment #3)
> > I see a lot of confusion in
> > kconf_update/spectacle-24.02.0-change_placeholder_format.cpp and
> > src/ExportManager.cpp files with "hh" and "HH". See attachment.
> > Are those string in the const ValueMap oldNewMap to be passwd to strftime?
> 
> spectacle-24.02.0-change_placeholder_format.cpp is a configuration migration
> script. It should have no impact on how the program actually works. Only
> ExportManager.cpp determines the behavior.

This is where I have found the "<ss>" string.
Comment 12 Noah Davis 2024-03-14 20:51:30 UTC
(In reply to 0BADC0DE from comment #10)
> What is your last placeholder in your configuration?
> If I have <ss> or <t> I get the weird behavior. I haven't checked all other
> placeholders, though.

I normally use the default setting (has <ss> at the end), but I also tried putting <t> at the end.
Comment 13 0BADC0DE 2024-03-15 08:25:38 UTC
(In reply to Noah Davis from comment #12)
> (In reply to 0BADC0DE from comment #10)
> > What is your last placeholder in your configuration?
> > If I have <ss> or <t> I get the weird behavior. I haven't checked all other
> > placeholders, though.
> 
> I normally use the default setting (has <ss> at the end), but I also tried
> putting <t> at the end.

Are you using the same version?
I am attaching a couple of new screenshots.
1. The saving path is not taken into consideration when doing "Save as". Maybe this is intentional.
2. The screenshot of spectacle shows clearly that the dialog is called without the <t> expansion.
Comment 14 0BADC0DE 2024-03-15 08:28:44 UTC
Created attachment 167237 [details]
Screenshot of Spetacle configuration with template and preview
Comment 15 0BADC0DE 2024-03-15 08:30:27 UTC
Created attachment 167238 [details]
While using "Save as". Suggested name has an unhandled partial placeholder.

Taking a screenshot of spectacle with spectacle itself is not really trivial.
You need to add a delay.
Please not the filenames of my screenshots.
Comment 16 Noah Davis 2024-03-15 09:45:31 UTC
(In reply to 0BADC0DE from comment #13)
> Are you using the same version?

I tested with git master and release/24.02 branches.

> I am attaching a couple of new screenshots.
> 1. The saving path is not taken into consideration when doing "Save as".
> Maybe this is intentional.

I'm not sure what you're referring to. If I click Save As, go to a folder in the dialog, and save in the dialog, the screenshot is saved there.

> 2. The screenshot of spectacle shows clearly that the dialog is called
> without the <t> expansion.

I cannot reproduce this behavior. <t> is always converted to a timezone abbreviation code for me.
Comment 17 0BADC0DE 2024-03-15 10:59:27 UTC
(In reply to Noah Davis from comment #16)
> > I am attaching a couple of new screenshots.
> > 1. The saving path is not taken into consideration when doing "Save as".
> > Maybe this is intentional.
> 
> I'm not sure what you're referring to. If I click Save As, go to a folder in
> the dialog, and save in the dialog, the screenshot is saved there.

See the proposed file name: it ends with "<t.png" .
This clearly shows that "<t>" is not converted into anything due to a 1-off character (">").

> > 2. The screenshot of spectacle shows clearly that the dialog is called
> > without the <t> expansion.
> 
> I cannot reproduce this behavior. <t> is always converted to a timezone
> abbreviation code for me.

But not here.
IS there a way to get logs from spectacle? Maybe it is an ArchLinux-introduced issue.
Comment 18 Noah Davis 2024-03-15 13:34:59 UTC
(In reply to 0BADC0DE from comment #17)
> IS there a way to get logs from spectacle? Maybe it is an ArchLinux-introduced issue.

No, but you can use GDB or LLDB. I doubt that Arch Linux introduced this issue, but that doesn't mean it's impossible.
Comment 19 Noah Davis 2024-03-15 13:44:07 UTC
(In reply to 0BADC0DE from comment #11)
> This is where I have found the "<ss>" string.

The base keys are defined in ExportManager::filenamePlaceholders. ExportManager::Placeholder makes plain (<key>) and html (&lt;key&gt;) versions of the keys. ExportManager::formattedFilename() turns the placeholders into the real text. tests/FilenameTest.cpp verifies that the placeholder keys are always turned into the real text.
Comment 20 0BADC0DE 2024-03-25 11:34:02 UTC
OK. I don't really mind where the error is. One thing is sure: I haven't recompiled/modified any source, still I am getting this error.
I even tried to use the "point-and-click" interface to define the file name template, with or without any interleaving "-" between fields.

My current template is:

SHOT-<yyyy><MM><dd><hh><mm><ss><t><title>

And my file names are like:

SHOT-20240325123131<t.png
Comment 21 0BADC0DE 2024-03-25 11:38:22 UTC
NEWS!

It only happens with "Rectangular region" captures (which is my default one).
With "Window under the pointer" (with a needed 3 sec delay to move the cursor) it gets the right file name!
Comment 22 Noah Davis 2024-03-25 14:08:54 UTC
OK, I figured out why I couldn't reproduce this. It actually has nothing to do with <t>, <ss> or hyphens, the problem is <title> when there is no actual title.
Comment 23 0BADC0DE 2024-03-25 14:27:39 UTC
It looks like this is it.
So, unless its is a screenshot of a titled window (a windowshot?), <title> should expand to something like "none" or "no_title" (or even "", the empty string) as that's the only case when we have a title.
Full screen or full desktop screenshots also haven't any.

TBH, besides "<title>" and "<#>" I would prefer to revert to strftime(3) placeholders as it has more options.
Maybe we'd move "<#>" to "%#"  and "<title>" to "%!" or anything else (only %i and %q and a few other ones are not used by strftime(3) ).
Comment 24 Noah Davis 2024-03-25 19:21:02 UTC
(In reply to 0BADC0DE from comment #23)
> TBH, besides "<title>" and "<#>" I would prefer to revert to strftime(3)
> placeholders as it has more options.
> Maybe we'd move "<#>" to "%#"  and "<title>" to "%!" or anything else (only
> %i and %q and a few other ones are not used by strftime(3) ).

Strftime was never used internally, the syntax of placeholders just looked similar. It's far easier to determine the start and end of a tag with <> than with % at only the beginning of a tag. This lets us create tags of arbitrary length easily. The <> tag syntax is far more flexible and readable. The next version of spectacle will have a lot more placeholder options, so whether or not strftime is used doesn't matter.
Comment 25 Natty 2024-04-03 21:51:09 UTC
This issue in particular seems to be a side effect of the switch from the percent syntax to the bracket syntax for placeholders in the file name. Since the path removes surrounding non-alphanumeric characters around the window title placeholder if missing, it consumes the bracket where there would be a (for example) %ss preceding it before, stopping at the second chacter s. So either the regex for trimming separators is too aggressive or the substitution happens too early, before other placeholders are substituted
Comment 26 Curie 2024-05-11 05:59:00 UTC
*** Bug 486542 has been marked as a duplicate of this bug. ***
Comment 27 Noah Davis 2024-05-15 17:22:45 UTC
It seems like there's no clear way to determine which kinds of characters count as separators that should be removed and which shouldn't
Comment 28 Bug Janitor Service 2024-05-15 17:23:30 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/spectacle/-/merge_requests/365
Comment 29 Noah Davis 2024-05-15 17:25:05 UTC
Git commit 8d2e0641af5bda4b7684d8d3da176f71e8b5c523 by Noah Davis.
Committed on 15/05/2024 at 17:22.
Pushed by ndavis into branch 'master'.

Fix empty <title> placeholders breaking nearby placeholders

M  +11   -5    src/ExportManager.cpp
M  +9    -0    tests/FilenameTest.cpp

https://invent.kde.org/graphics/spectacle/-/commit/8d2e0641af5bda4b7684d8d3da176f71e8b5c523
Comment 30 0BADC0DE 2024-05-15 17:34:53 UTC
I would revert back to the previous %-based syntax.

Honestly this move just broke something that was working fine without adding any extra feature.
Comment 31 Noah Davis 2024-05-15 20:08:33 UTC
(In reply to 0BADC0DE from comment #30)
> I would revert back to the previous %-based syntax.
> 
> Honestly this move just broke something that was working fine without adding
> any extra feature.

Objectively not true. There are a bunch of new placeholders that couldn't be added with the old syntax.
Comment 32 Noah Davis 2024-05-15 20:47:50 UTC
Git commit cac40b6fe828fa71dd3182b2f6839d49e9030dd0 by Noah Davis.
Committed on 15/05/2024 at 20:47.
Pushed by ndavis into branch 'release/24.05'.

Fix empty <title> placeholders breaking nearby placeholders
(cherry picked from commit 8d2e0641af5bda4b7684d8d3da176f71e8b5c523)

M  +11   -5    src/ExportManager.cpp
M  +9    -0    tests/FilenameTest.cpp

https://invent.kde.org/graphics/spectacle/-/commit/cac40b6fe828fa71dd3182b2f6839d49e9030dd0
Comment 33 0BADC0DE 2024-05-16 10:19:58 UTC
(In reply to Noah Davis from comment #31)
> (In reply to 0BADC0DE from comment #30)
> > I would revert back to the previous %-based syntax.
> > 
> > Honestly this move just broke something that was working fine without adding
> > any extra feature.
> 
> Objectively not true. There are a bunch of new placeholders that couldn't be
> added with the old syntax.

Not sure what you are talking about.
Besides the window title (which was already there) what will we have new to `strftime(3)` ?
Anyway, it's nice it is being fixed: <title> is not working yet.
Comment 34 Noah Davis 2024-05-16 13:39:05 UTC
(In reply to 0BADC0DE from comment #33)
> Not sure what you are talking about.
> Besides the window title (which was already there) what will we have new to
> `strftime(3)` ?
> Anyway, it's nice it is being fixed: <title> is not working yet.

The new features are in 24.05. Again, strftime was never used. The syntax only looked similar.