Dependency Graph

Dependency Graph
related to related to child of child of duplicate of duplicate of

View Issue Details

This bug affects 1 person(s).
 8
IDProjectCategoryView StatusLast Update
07805Bug reportsExpression Managerpublic2019-10-31 10:21
ReporterDenisChenu Assigned ToDenisChenu  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Product Version2.00+ 
Target Version2.05 RCFixed in Version2.05+ 
Summary07805: Comparaison String and Numeric is different in same page and other page
Description

When doing some comparaison in string and "strin can be numeric". EM don't return the same in same page and other page

Steps To Reproduce

Import survey attached and try some combination.

Additional Information

In javascript, we take value with $(QQ).text(); if this value can be numeric we force it to be numeric:

em_javascript.js line 594
return +value; // convert it to numeric return type

To have near the same issue in PHP, we do the same think:
$bNumericArg1 = is_numeric($arg1[0]) || $arg1[0] == '';

BUT when we compare, we can have some difference between js and PHP:

"A" > "1" is true in Javascript, but in em_core_helper: we do:
"A" > 1 even if we write QQ > "1".

TagsNo tags attached.
Attached Files
Bug heat8
Complete LimeSurvey version number (& build)130429
I will donate to the project if issue is resolvedNo
BrowserFF16
Database type & versionnot relevant
Server OS (if known)debian/linux
Webserver software & version (if known)apache
PHP VersionPHP Version 5.3

Relationships

related to 08217 closedDenisChenu "Numerical Input" question validation only client side 
parent of 08324 closedDenisChenu Broken numeric interpretation of answer codes. 
related to 12613 closedollehar Condition NAOK >= " " (no answer) evaluated differently in JS/PHP 
related to 14337 closedDenisChenu Broken numeric interpretation of answer codes 
related to 15501 closedollehar relevanceStatus : different evaluation in JS and PHP 
child of 07763 closedDenisChenu Answers not saved in database 

Activities

DenisChenu

DenisChenu

2013-04-29 16:18

developer   ~25164

Cartsen : think really EM PHP is the good solution here.

But change in javascript to have the same way than em/php seems to be a bad idea:
Use javascript comparaison seems really OK for me here.

Alternative is to force string compare in PHP if one is a string, but actaully we can't know if it:
QQ > 1 or QQ > "1" in equation editor then we have too different thing between js and php.

If we allways for string comparaison:
What for "2" and "2.1" and "10"

c_schmitz

c_schmitz

2013-09-19 13:39

administrator   ~26292

No matter how it works it, it should be consistent between PHP and Javascript.
I think at default we should go always go for string comparison. Can you have a go at it for 2.05?

DenisChenu

DenisChenu

2013-10-16 11:41

developer   ~26822

Use EM attribute isnumeric in JS and in PHP.

Seems it's OK, some test to do

I fix in pull request, because maybe it can break some Survey (using bug).

DenisChenu

DenisChenu

2013-10-21 12:40

developer   ~26870

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

c_schmitz

c_schmitz

2013-10-23 14:39

administrator   ~26948

2.05RC3 released

DenisChenu

DenisChenu

2013-11-15 19:04

developer   ~27202

Another solution:
$bNumericArg1 = ((is_numeric($arg1[0]) || $arg1[0] == '') && (!isset($arg1[2]) || $arg1[2]=='DQ_STRING' || $arg1[2]=='DS_STRING'));
$bNumericArg2 = ((is_numeric($arg2[0]) || $arg2[0] == '') && (!isset($arg2[2]) || $arg2[2]=='DQ_STRING' || $arg2[2]=='DS_STRING'));

Then :
"1" and '1' is string in JS and in PHP

Sam : are you OK or did you have an idea to have:
"1" and '1' number in JS ?

sammousa

sammousa

2013-11-21 10:48

reporter   ~27282

As discussed in IRC; i think if you quote it it's a string and if you don't it's a number.

If you use a variable then always try to interpret it, alternatively we could offer syntax like: 1 * A1 that would effectively force it to be a number.

DenisChenu

DenisChenu

2013-11-21 16:54

developer   ~27295

OK, then take it, not sure for "1"+QCODE+1 but let's try

DenisChenu

DenisChenu

2013-11-21 17:56

developer   ~27296

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

DenisChenu

DenisChenu

2013-11-21 18:00

developer   ~27297

Last edited: 2013-11-21 18:01

Now :don't find any difference in JS and PHP.
Comparaison between Question.NAOK can return allways false if one answer can be numeric. Then better is to use {""+QCODE>""+QCODE2} to have true.

Else :
A3>3 === 3>A3 === false

PS: put 2 new test lss file

c_schmitz

c_schmitz

2013-11-25 15:39

administrator   ~27388

2.05RC7 released.

Related Changesets

LimeSurvey: 2.05 28d42568

2013-10-18 09:10:53

DenisChenu

Details Diff
Fixed issue 07805: Comparaison String and Numeric is different in same page and other page
Dev: some test seems to fix issue
Dev: js use attr isnumeric, then add it to PHP too
Dev: Please do some test (but seems better than actually)
Affected Issues
07805
mod - application/helpers/common_helper.php Diff File
mod - application/helpers/expressions/em_core_helper.php Diff File
mod - application/helpers/expressions/em_manager_helper.php Diff File
mod - scripts/expressions/em_javascript.js Diff File
mod - scripts/survey_runtime.js Diff File

LimeSurvey: 2.05 2ff91165

2013-10-31 13:16:13

DenisChenu

Details Diff
Dev: fixed issue 08324: Broken numeric interpretation of answer codes.
Dev: this reopen 07805: because "1" is string in JS
Affected Issues
07805, 08324
mod - application/helpers/expressions/em_core_helper.php Diff File
mod - scripts/expressions/em_javascript.js Diff File

LimeSurvey: 2.05 fa699d03

2013-11-21 16:56:46

DenisChenu

Details Diff
Fixed issue 07805: Comparaison String and Numeric is different in same page and other page (second time)
Dev: keep the + for sum is 2 are numeric except if explicit STRING, then join
Dev: comparaison of Question result return allways false if one can be numerci and the other not
Dev: then if need compare string, better use ""+QCODE > ""+QCODE2
Affected Issues
07805
mod - application/helpers/expressions/em_core_helper.php Diff File

Issue History

Date Modified Username Field Change
2013-04-29 16:12 DenisChenu New Issue
2013-04-29 16:12 DenisChenu File Added: limesurvey_survey_EMJS-EMPHP.lss
2013-04-29 16:12 DenisChenu Relationship added child of 07763
2013-04-29 16:13 DenisChenu Issue Monitored: c_schmitz
2013-04-29 16:18 DenisChenu Note Added: 25164
2013-09-19 13:39 c_schmitz Note Added: 26292
2013-09-19 13:39 c_schmitz Target Version => 2.05 RC
2013-10-11 13:06 c_schmitz Assigned To => DenisChenu
2013-10-11 13:06 c_schmitz Status new => assigned
2013-10-11 13:06 DenisChenu Relationship added related to 08217
2013-10-16 11:41 DenisChenu Note Added: 26822
2013-10-18 11:29 DenisChenu File Added: limesurvey_survey_notsameDefault.lss
2013-10-18 11:33 DenisChenu File Added: limesurvey_survey_notsame-NOdefault.lss
2013-10-21 12:40 DenisChenu Changeset attached => LimeSurvey 2.05 28d42568
2013-10-21 12:40 DenisChenu Note Added: 26870
2013-10-21 12:40 DenisChenu Resolution open => fixed
2013-10-21 12:42 DenisChenu Status assigned => resolved
2013-10-21 12:42 DenisChenu Fixed in Version => 2.05+
2013-10-23 14:39 c_schmitz Note Added: 26948
2013-10-23 14:39 c_schmitz Status resolved => closed
2013-10-31 10:11 DenisChenu Relationship added parent of 08324
2013-10-31 14:18 DenisChenu Assigned To DenisChenu => sammousa
2013-10-31 14:18 DenisChenu Status closed => feedback
2013-10-31 14:18 DenisChenu Resolution fixed => reopened
2013-11-03 16:17 DenisChenu Changeset attached => LimeSurvey 2.05 2ff91165
2013-11-15 19:04 DenisChenu Note Added: 27202
2013-11-15 19:04 DenisChenu Status feedback => assigned
2013-11-21 10:48 sammousa Note Added: 27282
2013-11-21 16:54 DenisChenu Note Added: 27295
2013-11-21 16:54 DenisChenu Assigned To sammousa => DenisChenu
2013-11-21 17:56 DenisChenu Changeset attached => LimeSurvey 2.05 fa699d03
2013-11-21 17:56 DenisChenu Note Added: 27296
2013-11-21 17:57 DenisChenu File Added: limesurvey_survey_EMJS-EMPHP-add.lss
2013-11-21 17:57 DenisChenu File Added: limesurvey_survey_EMJS-EMPHP-compare.lss
2013-11-21 17:57 DenisChenu File Deleted: limesurvey_survey_EMJS-EMPHP.lss
2013-11-21 17:57 DenisChenu File Deleted: limesurvey_survey_notsameDefault.lss
2013-11-21 17:57 DenisChenu File Deleted: limesurvey_survey_notsame-NOdefault.lss
2013-11-21 18:00 DenisChenu Note Added: 27297
2013-11-21 18:00 DenisChenu Status assigned => resolved
2013-11-21 18:00 DenisChenu Resolution reopened => fixed
2013-11-21 18:01 DenisChenu Note Edited: 27297
2013-11-25 15:39 c_schmitz Note Added: 27388
2013-11-25 15:39 c_schmitz Status resolved => closed
2017-08-21 12:04 ollehar Relationship added related to 12613
2018-12-11 15:32 DenisChenu Relationship added related to 14337
2019-10-31 10:21 DenisChenu Relationship added related to 15501