View Issue Details

This bug affects 1 person(s).
 10
IDProjectCategoryView StatusLast Update
15532Feature requestsSurvey editingpublic2020-01-07 15:40
Reporterollehar Assigned ToDenisChenu  
PrioritynoneSeverityfeature 
Status closedResolutionfixed 
Summary15532: Show warnings when implicit alphabetical compare is used in expressions
Description

EM has no warning system. If an error is reported, the expression stops execution. We need warnings for alphabetical compare, which can be used by mistake by survey designers when they actually want numerical compare.

Problem: "2" < "18" is evaluated differently in PHP and JS. This feature will NOT fix evaluation, but instead show warnings when compare is used on strings.

Scenarios:

  1. User creates survey with two questions, Q1 and Q2
  2. Relevance equation for Q2 is Q1.NAOK < "10"
  3. A warning is shown in question summary AND survey logic file: "This expression uses alphabetical compare. Are you sure you didn't mean numerical compare? See this manual entry for more information."

  1. As above
  2. As above but with >, <= and >= operations
  3. As above

  1. User creates survey with two question groups G1 and G2
  2. User creates question Q1 in group G1
  3. Relevance equation for G2 is Q1.NAOK < "10"

  1. As above
  2. As above
  3. As above but with >, <= and >= operations

Should also work in the same way for subquestion relevance equations.

All scenarios above should also happen with "A10" or "qwerty" strings. It doesn't have to be a number inside the string. The manual entry should recommend users to use strcmp when comparing strings alphabetically, and to use intval/floatval with <, >, <=, >= when comparing numbers numerically.

The delivery should include functional and unit tests of the scenarios above.

Delivery should be done as a pull request on github.

TagsNo tags attached.
Bug heat10
Story point estimate
Users affected %

Relationships

related to 15501 closedollehar Bug reports relevanceStatus : different evaluation in JS and PHP 
parent of 15564 closedDenisChenu Bug reports Warnings shown for valid comparaison 
related to 15545 acknowledged Bug reports Survey logic file show valid question even if not valid 
related to 15547 new Bug reports Invalid error count on Survey Logic file for subquestion relevance 

Users monitoring this issue

jelo, DenisChenu

Activities

DenisChenu

DenisChenu

2019-11-05 13:04

developer   ~54397

Only for comparison ?
Warning on comparison or on forced string ?

ollehar

ollehar

2019-11-05 13:08

administrator   ~54398

Warning on operators <, >, <= and >= where at least one argument is a string. If both are numbers (e.g. by using intval before), there is no warning.

DenisChenu

DenisChenu

2019-11-05 14:04

developer   ~54399

Last edited: 2019-11-05 14:04

OK, then DS_STRING,DQ_STRING,STRING or WORD : right ?

ollehar

ollehar

2019-11-05 14:04

administrator   ~54400

Yeah, sounds right. +1

DenisChenu

DenisChenu

2019-11-06 16:32

developer   ~54434

Arg …

Q00_SQ001.NAOK >= 2 : OK find WORD and NUMBER
Q00_SQ001.NAOK >= '2' : OK find WORD and DS_STRING
intval(Q00_SQ001.NAOK) >= 2 : … previuous token is RP/° … i check if i can get the function type …

ollehar

ollehar

2019-11-06 16:33

administrator   ~54435

Hm, shouldn't you send us an offer before you start?

DenisChenu

DenisChenu

2019-11-06 16:38

developer   ~54436

Too hard for me …
Don't find how to find
(Q2.NAOK + "broke" + intval(Q00_SQ001.NAOK)) >= 2
for example …

Don't find where i get the result of a function (NUMBER or not)
https://github.com/LimeSurvey/LimeSurvey/blob/0b7ba655618bbea80dcc72294fb6dc8fcadf47e5/application/helpers/expressions/em_core_helper.php#L1858
but
https://github.com/LimeSurvey/LimeSurvey/blob/0b7ba655618bbea80dcc72294fb6dc8fcadf47e5/application/helpers/expressions/em_core_helper.php#L1978

gloups …

DenisChenu

DenisChenu

2019-11-06 16:40

developer   ~54437

I always check if i was able to do it in XX hour before starting :).

Here : clearly : need more than one day … and maybe more than one week (rewriting EM).

ollehar

ollehar

2019-11-06 16:43

administrator   ~54439

I hoped it would be enough to add code in https://github.com/LimeSurvey/LimeSurvey/blob/0b7ba655618bbea80dcc72294fb6dc8fcadf47e5/application/helpers/expressions/em_core_helper.php#L309?

ollehar

ollehar

2019-11-06 16:44

administrator   ~54440

Then check $bBothString

DenisChenu

DenisChenu

2019-11-06 17:06

developer   ~54443

No : it need to be in public function GetPrettyPrintString()

RDP_EvaluateBinary is only top do the final PHP part
see https://github.com/LimeSurvey/LimeSurvey/pull/1335

Adding a warning for '[0-9 ]' is really more easy … i make a pull request (free one)

DenisChenu

DenisChenu

2019-11-06 17:31

developer   ~54446

Maybe i have something , you're right : RDP_EvaluateBinary we ca,n create a new warnings array.

Tomorrow :)

ollehar

ollehar

2019-11-06 17:37

administrator   ~54448

+1

ollehar

ollehar

2019-11-06 17:38

administrator   ~54449

GetPrettyPrintString will collect warnings, but warnings are created in RDP_EvalBinary, same way as with the errors BUT does not halt execution. Also, warnings shown in yellow, not red. Etc etc.

DenisChenu

DenisChenu

2019-11-06 18:06

developer   ~54450

Yes,

I think i work on such system, tomorrow, can send pull request Friday.

DenisChenu

DenisChenu

2019-11-06 18:22

developer   ~54451

The manual entry should recommend users to use strcmp

… no link in title …

ollehar

ollehar

2019-11-07 10:15

administrator   ~54456

No link to where in which title?

DenisChenu

DenisChenu

2019-11-07 10:28

developer   ~54457

Since the warning is added here : https://github.com/LimeSurvey/LimeSurvey/blob/0b7ba655618bbea80dcc72294fb6dc8fcadf47e5/application/helpers/expressions/em_core_helper.php#L1333
No real way to add a link to the manual.

Can check to add a link inside the tooltip but … hard to click …

Only solution : rewrite ShowSurveyLogicFile. But its start to make a lot of update for a single warning …

ollehar

ollehar

2019-11-07 11:45

administrator   ~54459

OK, so maybe like this: A warning is an object, class EMWarning. Subclass warning into CompareEMWarning. If $em->warnings[] contains any CompareEMWarning, then add admin flash message about compare with link to manual.

E.g. like $bHaveError, could be $bHaveCompareWarning = true, then bla bla bla: https://github.com/LimeSurvey/LimeSurvey/blob/0b7ba655618bbea80dcc72294fb6dc8fcadf47e5/application/helpers/expressions/em_core_helper.php#L1306

DenisChenu

DenisChenu

2019-11-07 11:56

developer   ~54460

8-|

A flash even if the user WANT this compare ????

My opinion SurveyLogicFile is the best (except warning css in core admin theme is awfull …)

ollehar

ollehar

2019-11-07 13:09

administrator   ~54462

A flash in survey logic file check, I mean.

DenisChenu

DenisChenu

2019-11-07 16:07

developer   ~54468

I think of adding a line "wrning : blah blah" on question part …
If you have 30 warnings and 30 flash … 8-\

I push 1st part in some minutes

ollehar

ollehar

2019-11-07 17:03

administrator   ~54470

Warnings should be visible on every faulty equation like errors, I think. For flash: Definitely only one!

DenisChenu

DenisChenu

2019-11-07 17:55

developer   ~54471

Maybe best solution : https://github.com/LimeSurvey/LimeSurvey/pull/1341

But have the animation is not the best …

I added a warning with + https://github.com/LimeSurvey/LimeSurvey/pull/1341/commits/b7cd1c43c330c6211164c6a23e7248e4489c2d8c

DenisChenu

DenisChenu

2019-11-08 15:59

developer   ~54486

https://github.com/LimeSurvey/LimeSurvey/pull/1341

DenisChenu

DenisChenu

2019-11-11 10:53

developer   ~54497

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=29222

lime_release_bot

lime_release_bot

2019-11-11 14:55

administrator   ~54518

Fixed in Release 3.20.0+191112

Related Changesets

LimeSurvey: master f9a62f8d

2019-11-11 11:53

DenisChenu

Committer: ollehar


Details Diff
[READY] Fixed issue 15532: Show warnings when implicit alphabetical compare (#1341)

Fixed issue 15532: Show warnings when implicit alphabetical compare is used in expressions
Affected Issues
15532
mod - application/helpers/expressions/em_core_helper.php Diff File
mod - application/helpers/expressions/em_manager_helper.php Diff File
mod - application/helpers/viewHelper.php Diff File
mod - assets/styles-public/expressions.css Diff File
add - tests/controllers/ExpressionWarningsOnLogicTest.php Diff File
add - tests/data/surveys/limesurvey_survey_SurveyLogicWarnings.lss Diff File

Issue History

Date Modified Username Field Change
2019-11-05 11:38 ollehar New Issue
2019-11-05 11:48 ollehar Description Updated
2019-11-05 11:49 ollehar Description Updated
2019-11-05 11:49 ollehar Description Updated
2019-11-05 11:49 ollehar Description Updated
2019-11-05 11:54 ollehar Description Updated
2019-11-05 11:55 ollehar Description Updated
2019-11-05 11:58 ollehar Summary Show warnings when alphabetical compare is used in expressions => Show warnings when implicit alphabetical compare is used in expressions
2019-11-05 11:59 ollehar Description Updated
2019-11-05 12:07 ollehar Description Updated
2019-11-05 13:00 ollehar Description Updated
2019-11-05 13:04 DenisChenu Note Added: 54397
2019-11-05 13:08 ollehar Note Added: 54398
2019-11-05 14:04 DenisChenu Note Added: 54399
2019-11-05 14:04 DenisChenu Note Edited: 54399
2019-11-05 14:04 ollehar Note Added: 54400
2019-11-06 16:22 DenisChenu Issue Monitored: DenisChenu
2019-11-06 16:32 DenisChenu Note Added: 54434
2019-11-06 16:33 ollehar Note Added: 54435
2019-11-06 16:38 DenisChenu Note Added: 54436
2019-11-06 16:40 DenisChenu Note Added: 54437
2019-11-06 16:43 ollehar Note Added: 54439
2019-11-06 16:44 ollehar Note Added: 54440
2019-11-06 17:06 DenisChenu Note Added: 54443
2019-11-06 17:31 DenisChenu Note Added: 54446
2019-11-06 17:37 ollehar Note Added: 54448
2019-11-06 17:38 ollehar Note Added: 54449
2019-11-06 18:06 DenisChenu Note Added: 54450
2019-11-06 18:22 DenisChenu Note Added: 54451
2019-11-07 10:15 ollehar Note Added: 54456
2019-11-07 10:28 DenisChenu Note Added: 54457
2019-11-07 11:45 ollehar Note Added: 54459
2019-11-07 11:56 DenisChenu Note Added: 54460
2019-11-07 13:09 ollehar Note Added: 54462
2019-11-07 16:06 DenisChenu Assigned To => DenisChenu
2019-11-07 16:06 DenisChenu Status new => assigned
2019-11-07 16:07 DenisChenu Note Added: 54468
2019-11-07 17:03 ollehar Note Added: 54470
2019-11-07 17:55 DenisChenu Note Added: 54471
2019-11-07 18:05 DenisChenu Relationship added related to 15545
2019-11-08 08:05 DenisChenu Relationship added related to 15547
2019-11-08 15:54 DenisChenu Relationship added related to 15501
2019-11-08 15:59 DenisChenu Assigned To DenisChenu => ollehar
2019-11-08 15:59 DenisChenu Status assigned => ready for testing
2019-11-08 15:59 DenisChenu Note Added: 54486
2019-11-11 10:53 ollehar Changeset attached => LimeSurvey master f9a62f8d
2019-11-11 10:53 DenisChenu Note Added: 54497
2019-11-11 10:53 DenisChenu Assigned To ollehar => DenisChenu
2019-11-11 10:53 DenisChenu Resolution open => fixed
2019-11-11 14:55 lime_release_bot Note Added: 54518
2019-11-11 14:55 lime_release_bot Status ready for testing => closed
2019-11-14 17:34 DenisChenu Relationship added parent of 15564
2020-01-07 15:40 jelo Issue Monitored: jelo
2021-08-02 17:37 guest Bug heat 6 => 10