Bug 431362

Summary: Can no longer parse some hexadecimal input
Product: [Plasma] krunner Reporter: Luke-Jr <luke-jr+kdebugs>
Component: calculatorAssignee: Alexander Lohnau <alexander.lohnau>
Status: RESOLVED FIXED    
Severity: normal CC: nate, ped, plasma-bugs
Priority: HI Keywords: regression
Version: 5.20.4   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 5.21.1

Description Luke-Jr 2021-01-09 18:11:00 UTC
SUMMARY


STEPS TO REPRODUCE
1. Open KRunner
2. Enter 0x1ff=

OBSERVED RESULT
Answer given as 0

EXPECTED RESULT
Answer of 511

ADDITIONAL INFORMATION
This used to work
Comment 1 Nate Graham 2021-01-12 00:04:34 UTC
Confirmed.
Comment 2 Alexander Lohnau 2021-01-12 15:50:56 UTC
Does "=hex(1ff)" work as expected?

The issue seems that the x is interpreted as a multiplication operator. This was a feature request some time ago.

Do you think it would be a good idea to exclude "0xwhatever" queries from this rule?
Comment 3 Nate Graham 2021-01-12 15:52:14 UTC
(In reply to Alexander Lohnau from comment #2)
> Does "=hex(1ff)" work as expected?
Yep, works for me.

> The issue seems that the x is interpreted as a multiplication operator. This
> was a feature request some time ago.
> 
> Do you think it would be a good idea to exclude "0xwhatever" queries from
> this rule?
I think that makes sense.
Comment 4 Nate Graham 2021-01-13 17:14:44 UTC
*** Bug 431285 has been marked as a duplicate of this bug. ***
Comment 5 Alexander Lohnau 2021-01-13 19:35:55 UTC
Git commit 292d9d19250a81757128666c6b3784c41b3e1697 by Alexander Lohnau.
Committed on 13/01/2021 at 19:22.
Pushed by alex into branch 'master'.

calculator runner: Fix handling of hexadecimal input/output

- In case our query starts with 0x123abc we do not call
the `userFriendlyMultiplication` method which replaces the
x sign with the multiplication operator.
We can be sure that the user wants to parse a hex
value. Also the `=` is not mandatory anymore.
- The hex=mydecimalnumber functionality was broken.
The conversion of the hex value is only done inside of the
if statement and before the values will be the same, unless we do some math operation.

Test Plan:
`=0xf` returns 15
`0xf` return 15
`7x7` returns 49
`hex=15` returns 0xF
`hex=14+1` returns 0xF
FIXED-IN: 5.21

M  +7    -4    runners/calculator/calculatorrunner.cpp

https://invent.kde.org/plasma/plasma-workspace/commit/292d9d19250a81757128666c6b3784c41b3e1697
Comment 6 Peter Ped Helcmanovsky 2021-02-17 21:54:47 UTC
So, in trivial cases it now works, but for non-trivial expressions it still leads to wrong results, like:
=0x12+1  -> 19
=1+0x12  -> 1

While I get why the feature was added (for less tech users), it caused me already quite a disruption in my own usage, as I never expect it and sometimes it takes me some time to realize the result was actually wrong and I have to evade it with "0X" instead.

I mean with 5.21 I will run into it lot less, as I mostly put hexa numbers at beginning of expression or convert only single number, but I'm not sure if that makes it actually even worse, because it may be more difficult to spot the result is wrong.
Comment 7 Alexander Lohnau 2021-02-18 07:16:42 UTC
I will try to write a fix for that in this week.
Comment 8 Alexander Lohnau 2021-02-22 19:19:23 UTC
Git commit ef4d5d0f6868fa6f010eaa6b427c5e84519eb37e by Alexander Lohnau.
Committed on 22/02/2021 at 17:27.
Pushed by alex into branch 'master'.

calculatorrunner: Fix mixed hex+decimal calculations
FIXED-IN: 5.21.1

M  +1    -1    runners/calculator/calculatorrunner.cpp

https://invent.kde.org/plasma/plasma-workspace/commit/ef4d5d0f6868fa6f010eaa6b427c5e84519eb37e
Comment 9 Alexander Lohnau 2021-02-22 21:22:52 UTC
Git commit a3b017ccb56be918163fed350e181ec4fd57db73 by Alexander Lohnau.
Committed on 22/02/2021 at 19:45.
Pushed by alex into branch 'Plasma/5.21'.

calculatorrunner: Fix mixed hex+decimal calculations
FIXED-IN: 5.21.1

M  +1    -1    runners/calculator/calculatorrunner.cpp

https://invent.kde.org/plasma/plasma-workspace/commit/a3b017ccb56be918163fed350e181ec4fd57db73