Invalid return of the last characters for the button parameters

Bug reports will be moved here when the described bug has been fixed

Moderators: petermad, Stefan2, white, Hacker

Fla$her
Power Member
Power Member
Posts: 2874
Joined: 2020-01-18, 04:03 UTC

Invalid return of the last characters for the button parameters

Post by *Fla$her »

C:\dir\Name.ext under the cursor.

Results:

%P:~-1 = \
%P:~-2 = r\
%P:~-3 = ir
%P:~-4 = di
%P:~-5 = \d
etc.

%N:~-1 = t
%N:~-2 = xt
%N:~-3 = ex
%N:~-4 = .e
%N:~-5 = e.
etc.

%O:~-1 = e
%O:~-2 = me
%O:~-3 = am
%O:~-4 = Na
%O:~-5 = Na
etc.
Overquoting is evil! 👎
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50254
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Invalid return of the last characters for the button parameters

Post by *ghisler(Author) »

The syntax is ~start,length but you only specified ~start which is undefined. What should it do?

From the help:
Note: All parameters now support substring fields in the form :~start,length, e.g. %N:~2,5 or %N:~-8,5 . To append a number directly after the length value, use another ~ character, e.g. %N:~2,5~2. Negative values are measured from the end of the string. Example: %P:~0,-1 cuts off the backslash from the path.
The Start value -0 is special: %N:~-0,20 copies the first 20 characters of the name without extension, %N:~-0,-20 the first 20 characters of the extension without the name.
There are two possibilities:
1. Batch files insert the entire rest of the string from the given start position. For example,
echo %ComSpec:~3%
returns
WINDOWS\system32\cmd.exe
2. In the multi-rename tool, [N3] only inserts the 3rd character.
Author of Total Commander
https://www.ghisler.com
Fla$her
Power Member
Power Member
Posts: 2874
Joined: 2020-01-18, 04:03 UTC

Re: Invalid return of the last characters for the button parameters

Post by *Fla$her »

What should it do?
The title of the topic reads: "... the last characters for the button parameters".
Obviously, the behavior should match cmd. echo %ComSpec:~-3% returns 'exe', as expected.
Green indicates correct behavior, red indicates incorrect behavior. I thought it was also obvious.
Overquoting is evil! 👎
User avatar
white
Power Member
Power Member
Posts: 5654
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: Invalid return of the last characters for the button parameters

Post by *white »

Since the implementation is very similar to cmd.exe, I think user expectation will often be that TC behaves the same way. Furthermore substring functions in various programming languages work that way when you leave out the length parameter. The use of the comma strengthens this expectation.

I don't think you can really compare it to the placeholders in the multi rename-tool (MRT). For starters, [N1] means the first character, while :~1 means the second character. That alone sets it apart completely. Furthermore, the placeholders in the MRT not only have a syntax with a comma, but also with a minus sign (2-5 means characters 2 to 5), and the syntax for taking the remaining characters is using the minus sign without a number following it.

I think the only reason that makes sense for assuming 1 character when no length is specified, is for compatibility reasons. Although the functionality was undocumented, it partially worked that way and people may be using it. Note that when using a positive index number higher than 9, it also fails (for example %N:~10).

All things considered, I would still choose for the syntax similar to cmd.exe.
Fla$her
Power Member
Power Member
Posts: 2874
Joined: 2020-01-18, 04:03 UTC

Re: Invalid return of the last characters for the button parameters

Post by *Fla$her »

Yes, it's like str.slice([-]start[, length]) in JS or Mid(Str, start[, length]) in VB, where the second parameter is optional.
Overquoting is evil! 👎
JOUBE
Power Member
Power Member
Posts: 1653
Joined: 2004-07-08, 08:58 UTC

Re: Invalid return of the last characters for the button parameters

Post by *JOUBE »

"People" may think this is a suggestion, but not a bug, so move it to forum suggestions...
Fla$her
Power Member
Power Member
Posts: 2874
Joined: 2020-01-18, 04:03 UTC

Re: Invalid return of the last characters for the button parameters

Post by *Fla$her »

For me, this is definitely a bug, because there is a violation of the consistency of right and wrong behavior, which is reflected in the examples.
Overquoting is evil! 👎
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50254
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Invalid return of the last characters for the button parameters

Post by *ghisler(Author) »

This should be fixed in RC3, please test it!
26.01.25 Fixed: Button bar, partial parameters like %P:start,len: If len isn't specified, keep all characters until the end, e.g. %P:4 (32/64)
Author of Total Commander
https://www.ghisler.com
User avatar
white
Power Member
Power Member
Posts: 5654
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: Invalid return of the last characters for the button parameters

Post by *white »

Tested OK using TC 11.51rc3 32-bit and 64-bit.
Fla$her
Power Member
Power Member
Posts: 2874
Joined: 2020-01-18, 04:03 UTC

Re: Invalid return of the last characters for the button parameters

Post by *Fla$her »

Yes, it's fixed. Thanks!
The character '~' is missing:
ghisler(Author) wrote: 2025-01-28, 11:16 UTC
..., e.g. %P:~4 (32/64)
It's also worth pointing out in the help that <start> can be negative for capturing the last characters.

Related question: is it correct to leave quotation marks for parameters like %N:~<s>,<l> (%V, %C1, %R1, %S1), even if there are spaces left?
In theory, quotation marks are only needed for existing files/folders. Why use quotation marks for changed names? I think they should be removed, regardless of the presence of %Q.
Overquoting is evil! 👎
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50254
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Invalid return of the last characters for the button parameters

Post by *ghisler(Author) »

Thanks for confirming the fix!
The character '~' is missing:
Fixed in the online history1151.txt.
It's also worth pointing out in the help that <start> can be negative for capturing the last characters.
Already explained in the help, it also works for <length>, which is then measured from the end of the file:

Code: Select all

Negative values are measured from the end of the string.
Related question: is it correct to leave quotation marks for parameters like %N:~<s>,<l> (%V, %C1, %R1, %S1), even if there are spaces left?
Yes, quotes are used when the resulting string contains at least one space. It has nothing to do with existing or not existing files, but with the separation of command lines into multiple parts by cmd.exe.
Author of Total Commander
https://www.ghisler.com
Fla$her
Power Member
Power Member
Posts: 2874
Joined: 2020-01-18, 04:03 UTC

Re: Invalid return of the last characters for the button parameters

Post by *Fla$her »

Already explained in the help,
OK. Sorry, I accidentally opened the previous version.
but with the separation of command lines into multiple parts by cmd.exe.
I understand that. But when the string is changed, only a substring remains, which participates in merging with custom substrings. Therefore, it's correct that quotes for the user remain optional, i.e. "Prefix%N:~-4Suffix".
You didn't add quotation marks for %O and %E, which are also substrings, so the same logic should apply here.

Or imagine that you need to write cmd /c if "%N:~,5"=="Pref " copy %N "%T"
I don't think it makes sense to add %Q to every such entry, since this will have to be done all the time.
Overquoting is evil! 👎
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50254
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Invalid return of the last characters for the button parameters

Post by *ghisler(Author) »

Sorry, there are too many cases to decide when to add quotes and when not. If you don't like the quotes, just use %Q once and all automatic quotation marks will be omitted. automatic quotes are only added to %N, %M, and their combinations with %P and %T, plus %S and %R.

Since the original bug was fixed, I'm moving this thread to fixed bugs.

Moderator message from: ghisler(Author) » 2025-01-30, 08:11 UTC

Moved to fixed bugs
Author of Total Commander
https://www.ghisler.com
Fla$her
Power Member
Power Member
Posts: 2874
Joined: 2020-01-18, 04:03 UTC

Re: Invalid return of the last characters for the button parameters

Post by *Fla$her »

If you don't like the quotes, just use %Q once and all automatic quotation marks will be omitted.
Have you read this? >
Fla$her wrote:I don't think it makes sense to add %Q to every such entry, since this will have to be done all the time.

automatic quotes are only added to .. %M
It's not true.
Last edited by Fla$her on 2025-01-30, 16:10 UTC, edited 1 time in total.
Overquoting is evil! 👎
User avatar
petermad
Power Member
Power Member
Posts: 15914
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Invalid return of the last characters for the button parameters

Post by *petermad »

It's not true.
YES - as pointed out here a long time ago: viewtopic.php?t=76443

When even the author cannot remember this inconsistency, perhaps it is time to make quoting of %N and %M consistent.
License #524 (1994)
Danish Total Commander Translator
TC 11.51rc2 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1390a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Post Reply