View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
12613 | Bug reports | Survey taking | public | 2017-08-21 10:47 | 2021-03-10 17:10 |
Reporter | ollehar | Assigned To | ollehar | ||
Priority | none | Severity | partial_block | ||
Status | closed | Resolution | reopened | ||
Product Version | 2.67.x | ||||
Summary | 12613: Condition NAOK >= " " (no answer) evaluated differently in JS/PHP | ||||
Description | Title. Possible solutions: 1) Use the tokenized expression and parse it using a small VM which can be copied to JS. Instead of generating JS code, we send the tokens to the client. 2) Use JavaScript on the server to make sure the evaluation is exactly the same as on the client | ||||
Steps To Reproduce | Activate attached survey, run it, answer for second question is not recorded in database. | ||||
Tags | No tags attached. | ||||
Attached Files | |||||
Bug heat | 16 | ||||
Complete LimeSurvey version number (& build) | latest | ||||
I will donate to the project if issue is resolved | No | ||||
Browser | - | ||||
Database type & version | - | ||||
Server OS (if known) | - | ||||
Webserver software & version (if known) | - | ||||
PHP Version | - | ||||
related to | 07805 | closed | DenisChenu | Comparaison String and Numeric is different in same page and other page |
related to | 15501 | closed | ollehar | relevanceStatus : different evaluation in JS and PHP |
GetJavaScriptEquivalentOfExpression() does not check for arguments type mismatch. |
|
@DenisChenu On vacation, still? |
|
Coming back now … The didn't test for "arguments type mismatch" is needed. Because with single choice answer : it's a code, the "1" is a string … forcing to numeric if comparaison is done with a number PHP compare is done here : https://github.com/LimeSurvey/LimeSurvey/blob/master/application/helpers/expressions/em_core_helper.php#L288 |
|
Care to join me on IRC? |
|
Eating before , come on irc this afternoon. I test with the survey |
|
Great! :) A customer had this problem on LimeService, and I've confirmed it. We need to generate type mismatch code for the JS part too, not only PHP. |
|
I will look into how to unit-test JavaScript together with PHPUnit. |
|
It's not empty, it's space … tehn there are a mismatch type with PHP => false , but return true in JS … only with space or with empty string too ? |
|
The space is not a problem. JS: 1 >= " " ---> true PHP: false >= " " ---> false Why "false" and not 1? Because of type mismatch check. |
|
JS: 1 >= "!" or 1 >= "A" or 1 <= "!" or 1 <= "A" ---> false (even if char code is lesser). Maybe a javascript in 2.6lts See new lss http://demonstration.sondages.pro/563168?newtest=Y |
|
See Using the Equality Operators on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators When comparing a number and a string, the string is converted to a number value. JavaScript attempts to convert the string numeric literal to a Number type value. First, a mathematical value is derived from the string numeric literal. Next, this value is rounded to nearest Number type value. |
|
You're overthinking this. The type mismatch transform 1 >= " " into false >= " " Dump in RDP_EvaluateBinary() for details. |
|
Maybe more relevant: When constructing a condition, the empty string is used to represent "No answer". |
|
RDP_EvaluateBinary : result is an array : 0: the result, 1: don't remind and 2: the value type for EM next function And we already have a specific fix for JS comparaison for le (i don't add it, surely since 1.92) |
|
See another updated lss file. tested on 2.67.3 Try with -1 on q1 : same error with " ", but seems there are an issue with "" (emty string) too … � |
|
Some other approaches:
|
|
I think there are 2 bugs here :). 1st : no answer IS "" not a space (test with is-empty for example) |
|
|
|
PS : the test done is … strange … and there are no valide answer. -1 < no-answer or not ? |
|
Valid answer or not is not important. Only thing that matters is that PHP and JS does the same thing. |
|
Yes :). 1st part : make a complete test with pure javascript to test (for example) 1 < "A" , 1 < " ", 1 < "!" etc … if "number" : js cast it as string (sure at 99.9942%) What do you think of this step ? |
|
Some input from stackoverflow: https://stackoverflow.com/questions/45858228/evaluate-binary-operations-in-both-php-and-javascript |
|
-1 < 'A' ---> false in JavaScript but var v = -1 |
|
About 1st part: That's basically what I'm doing already in my unit tests. You think the problem is that JavaScript casts numbers to strings at certain points, and PHP does not? |
|
Chapter about type coersion in JavaScript: https://www.safaribooksonline.com/library/view/you-dont-know/9781491905159/ch04.html Another problem: EM in PHP does not know at evaluation if the function is onlynumber. Look at this: "0" == " " EM will treat this as is in PHP, "0" == " ", which is false, but in JS LEMval("0") will return 0, not "0", because onlynum = 1, and 0 == " " is true in JS. |
|
-1 < 'A or 1 < 'A' or 1 <= 'A' or … -1 <= '!' => always false. It's the reason of " "arguments type mismatch" part … because PHP cast as string by default … excet with space … (and empty : empty is 0). Seems javascript set " " to "" then to 0 … |
|
Sure. I was talking about the logic in LEMval(), which will cast "0" to 0, but this doesn't happen in PHP. Basically, I think EM needs to know about the onlynum property, too. |
|
Another idea: Scrap <, >, <= etc and replace them with LEMcompare(operation, type, arg1, arg2) to get precise control over type-casting. |
|
0 == " " : yes seems when using " " , javascript just trim it Maybe we must treat like '' and '0' , see https://github.com/LimeSurvey/LimeSurvey/blob/master/application/helpers/expressions/em_core_helper.php#L370 Then this fix THIS issue ;) |
|
Yes, I will try that, might fix it for ==. |
|
Something like : $bNumericArg2 = !trim($arg2[0]) || strval(floatval($arg2[0]))==strval($arg2[0]); https://github.com/LimeSurvey/LimeSurvey/blob/c21c16f990894859626efe28f0749f727b7a4a90/application/helpers/expressions/em_core_helper.php#L287 But need test with " 0 " in js. |
|
Someone already use === in expression ? |
|
My tests run JS too, just tell me which expression to add. |
|
Maybe : '0' : replace by [space] , '!' (before number in ascii), 'A' (after number in ascii), '0xA' (numeric in PHP not in js), '001.100' (DB and 'maybe' lemval under condition). comparaison A lot can be added … '0xA' with 17 and 15 : but i think there are an issue currently |
|
Does this issue only appear for numerical questions? |
|
The answer is no, I can reproduce it with short text question, too. |
|
I think this is not possible to solve without knowing the question type in EM core, if it's numerical or not, since LEMval() behaves different in that case. So how to add that context in EM core? |
|
EM core : WORD or NUMBER if i don't make error … |
|
NUMBER == isnumeric in js. |
|
BUT : LEMval do : "1" to 1 with any question type not only for numeric question type. |
|
I get all WORD, even for numerical type. |
|
@ollehar : i work on string/numeric comparaison currently https://bugs.limesurvey.org/view.php?id=14337#c52311 Seems PHP need something like this:
Maybe it can fix this part too. |
|
Phew... I don't really have the head space to dig into this, but I can help you run the EM tests I created for this bug. It's marked as skipped right now. You need to install NodeJS to run JavaScript without the browser. |
|
PS : i do a pull request but only next week.
|
|
I'd recommend to NOT change anything before having a proper test suite. The chances of breaking something else is very big. :| |
|
Yes, i know it's the reason why i only fix '5' < '20' in https://bugs.limesurvey.org/view.php?id=14337 |
|
A precision about type, currently there are, for PHP
|
|
Date Modified | Username | Field | Change |
---|---|---|---|
2017-08-21 10:47 | ollehar | New Issue | |
2017-08-21 10:47 | ollehar | Status | new => assigned |
2017-08-21 10:47 | ollehar | Assigned To | => ollehar |
2017-08-21 10:47 | ollehar | File Added: limesurvey_survey_563168.lss | |
2017-08-21 12:01 | ollehar | Note Added: 44316 | |
2017-08-21 12:04 | ollehar | Relationship added | related to 07805 |
2017-08-21 12:24 | ollehar | Note Added: 44317 | |
2017-08-21 12:27 | ollehar | Note Added: 44318 | |
2017-08-21 12:27 | ollehar | Note Added: 44319 | |
2017-08-21 12:32 | DenisChenu | Note Added: 44320 | |
2017-08-21 12:33 | ollehar | Note Added: 44321 | |
2017-08-21 12:38 | DenisChenu | Note Added: 44322 | |
2017-08-21 12:39 | ollehar | Note Added: 44323 | |
2017-08-21 12:39 | ollehar | Note Added: 44324 | |
2017-08-21 12:42 | DenisChenu | Note Added: 44325 | |
2017-08-21 12:44 | ollehar | Note Added: 44326 | |
2017-08-21 12:53 | DenisChenu | File Added: limesurvey_survey_emptyMoreTest.lss | |
2017-08-21 12:53 | DenisChenu | Note Added: 44327 | |
2017-08-21 13:05 | DenisChenu | Note Added: 44328 | |
2017-08-21 13:16 | ollehar | Note Added: 44329 | |
2017-08-21 14:10 | ollehar | Note Added: 44330 | |
2017-08-21 14:12 | ollehar | File Added: Selection_263.png | |
2017-08-21 14:12 | ollehar | File Added: Selection_262.png | |
2017-08-21 14:49 | DenisChenu | Note Added: 44331 | |
2017-08-21 15:06 | DenisChenu | File Added: limesurvey_survey_emptyMoreMoreTest.lss | |
2017-08-21 15:06 | DenisChenu | Note Added: 44332 | |
2017-08-24 11:19 | ollehar | Note Added: 44338 | |
2017-08-24 11:20 | ollehar | Note Edited: 44338 | |
2017-08-24 11:22 | ollehar | Note Edited: 44338 | |
2017-08-24 11:22 | ollehar | Note Edited: 44338 | |
2017-08-24 11:32 | DenisChenu | Note Added: 44339 | |
2017-08-24 11:33 | ollehar | Note Added: 44340 | |
2017-08-24 11:44 | DenisChenu | Note Added: 44341 | |
2017-08-24 11:46 | ollehar | Note Added: 44342 | |
2017-08-24 11:50 | DenisChenu | Note Added: 44343 | |
2017-08-24 11:54 | ollehar | Note Added: 44344 | |
2017-08-24 11:56 | ollehar | Note Added: 44345 | |
2017-08-24 12:01 | ollehar | Note Added: 44346 | |
2017-08-24 12:57 | ollehar | Note Added: 44347 | |
2017-08-24 13:00 | DenisChenu | Note Added: 44348 | |
2017-08-24 13:04 | ollehar | Note Added: 44349 | |
2017-08-24 13:21 | ollehar | Note Added: 44350 | |
2017-08-24 14:18 | DenisChenu | Note Added: 44351 | |
2017-08-24 14:19 | ollehar | Note Added: 44352 | |
2017-08-24 14:19 | DenisChenu | Note Added: 44353 | |
2017-08-24 14:25 | DenisChenu | Note Added: 44354 | |
2017-08-24 14:26 | ollehar | Note Added: 44355 | |
2017-08-24 14:52 | DenisChenu | Note Added: 44356 | |
2017-08-24 14:53 | DenisChenu | Note Edited: 44356 | |
2017-08-28 15:55 | ollehar | Note Added: 44372 | |
2017-08-28 16:31 | ollehar | File Added: limesurvey_survey_248764.lss | |
2017-08-28 16:31 | ollehar | Note Added: 44373 | |
2017-08-28 16:50 | ollehar | Note Added: 44374 | |
2017-08-28 16:50 | ollehar | Note Edited: 44374 | |
2017-08-28 16:57 | DenisChenu | Note Added: 44375 | |
2017-08-28 16:58 | DenisChenu | Note Added: 44376 | |
2017-08-28 17:02 | DenisChenu | Note Added: 44377 | |
2017-08-28 17:02 | ollehar | Note Added: 44378 | |
2019-06-06 09:03 | DenisChenu | Note Added: 52312 | |
2019-06-06 09:03 | DenisChenu | Note Edited: 52312 | |
2019-06-06 10:26 | ollehar | Note Added: 52315 | |
2019-06-13 10:49 | ollehar | Description Updated | |
2019-06-13 10:50 | ollehar | Description Updated | |
2019-06-13 10:58 | DenisChenu | Issue Monitored: DenisChenu | |
2019-06-13 11:07 | DenisChenu | Note Added: 52383 | |
2019-06-13 11:16 | ollehar | Note Added: 52384 | |
2019-06-13 11:36 | DenisChenu | Note Added: 52386 | |
2019-06-14 08:50 | DenisChenu | Note Added: 52410 | |
2019-10-31 10:21 | DenisChenu | Relationship added | related to 15501 |
2020-03-13 18:47 | c_schmitz | Status | assigned => closed |
2020-03-14 10:35 | c_schmitz | Status | closed => new |
2020-03-14 10:35 | c_schmitz | Resolution | open => reopened |
2021-03-10 17:10 | ollehar | Status | new => closed |
2021-08-02 16:13 | guest | Bug heat | 14 => 16 |