Ticket #4422 - Input validation with forward slash

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
jasincole
Posts: 6
Joined: Fri Aug 07, 2020 10:06 am

Ticket #4422 - Input validation with forward slash

Postby jasincole » Sun Sep 13, 2020 9:17 pm

Hello, New here but I think this is a very valid issue and may be outside the scope of freecad.

The issue is with "/" when inputting a length into multiple input boxes inside more than one workbench. Check the ticket for a basic understanding of the bug. I've now verified this in the sketch workbench and part workbench. I've tried to track this down and I don't come up with much inside of freecad, in fact it looks to be more specific to third party source code. I might be wrong about this, while i try and debug if I break during input it says the code broke outside of freecad.

For instance:

case #1
1" is present inside of text box, you select the box and put cursor after 1 and before ", now press / and nothing will be input.
Case #2
1/2" is present inside of text box, you select the box and put cursor after the 2 and before ", now backspace and nothing happens.

In case 1 and 2 you can remove the " mark and the problem goes away. It is also not specific to and inch ("). Same thing happens if 'in' exist while while inputting a / before the 'in'.

Case #3
if you have 1" present inside of text box , you select the box and put cursor after the 1 and before ", now add "+1/2" and its valid. Adding in the + changes the way the / seems to be interpreted. Same thing if you have 4+1/2" and you try and backspace just the 2, it's valid.

This is repeatable all over freecad, which makes me believe it goes further down the rabbit hole than just freecad. I'd like to hear some suggestions on where to look from a more experienced developer.
User avatar
Kunda1
Posts: 7986
Joined: Thu Jan 05, 2017 9:03 pm

Re: Ticket #4422 - Input validation with forward slash

Postby Kunda1 » Sun Sep 13, 2020 9:57 pm

issue #4422 (linked back to ticket)
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
chrisb
Posts: 26920
Joined: Tue Mar 17, 2015 9:14 am

Re: Ticket #4422 - Input validation with forward slash

Postby chrisb » Sun Sep 13, 2020 11:19 pm

This is a known issue, and you should have obeyed the big yellow banner in the tracker and have discussed it here first. You can input expressions containing / by using brackets around them.
wmayer
Site Admin
Posts: 16265
Joined: Thu Feb 19, 2009 10:32 am

Re: Ticket #4422 - Input validation with forward slash

Postby wmayer » Mon Sep 14, 2020 8:16 am

The problem is the grammar of the quantity parser. When using the +,-,* operator to have an expression like this:

Code: Select all

App.Units.parseQuantity("12 + mm")
App.Units.parseQuantity("12 - mm")
App.Units.parseQuantity("12 * mm")
The parser raises an error that this is not supported. Internally it's then assumed that the user input is not complete yet (intermediate state) and thus the content is not changed.

Now the problem is when using the / operator:

Code: Select all

App.Units.parseQuantity("12 / mm")
The parser supports this expression and determines a quantity of "1/length". But because in this context the quantity must be "length" the input is considered as invalid (in contrast to intermediate) and thus the input is auto-rejected and replaced by the last valid input.

So, if your input was "12 mm" and you changed it to "12 / mm" it will be replaced again with "12 mm".
openBrain
Posts: 4506
Joined: Fri Nov 09, 2018 5:38 pm

Re: Ticket #4422 - Input validation with forward slash

Postby openBrain » Mon Sep 14, 2020 8:38 am

This is a duplicate. Already known and tracked. There is an open PR from realthunder dealing with the parsers that should solve. I didn't test the PR yet.
wmayer
Site Admin
Posts: 16265
Joined: Thu Feb 19, 2009 10:32 am

Re: Ticket #4422 - Input validation with forward slash

Postby wmayer » Mon Sep 14, 2020 8:38 am