View Issue Details

This bug affects 1 person(s).
 4
IDProjectCategoryView StatusLast Update
06171Bug reportsSurvey takingpublic2012-06-20 16:43
ReporterTMSWhite Assigned ToTMSWhite  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Product Version1.92+ 
Fixed in Version1.92+ 
Summary06171: variable < X is true even if variable isn't answered
Description

This is a known limitation from Expression Manager. Opening this as a bug so that users are aware of it (and on the off chance that someone can figure out a solution).

Additional Information

Version 1.92 gives different answers for less-than / greater-than comparisons against empty values compared to earlier versions.
One of the LimeSurvey demo surveys uses a set of conditions that translates to this relevance equation: {(age < 16) or (age == 20) or ... or (age == 80)}. In LimeSurvey 1.91+, (age < 16) is FALSE when there is no answer (the value is blank). However, in LimeSurey 1.92, (age < 16) is TRUE when there is no answer, since both PHP and JavaScript treat blank as 0 in mathematical comparisons. Thus, 1.91+ would hide that question when age was unanswered, but 1.92 would show it.

We went to great pains to prevent this, but since we needed to have the Expressions generate identical results in PHP and JavaScript, there was no way to make 1.92 treat "" < 16 as FALSE. Fortunately, there is an easy work-around for this. If you want (age < 16) to be FALSE, then use this expression instead: {(!is_empty(age) and age < 16)}. You can use the new Survey Logic File view to quickly identify and fix any such comparisons in your survey.

TagsNo tags attached.
Attached Files
emptymath1.jpg (134,128 bytes)
emptymath2.jpg (146,767 bytes)
emptymath3.jpg (215,388 bytes)
emptymath5.jpg (168,406 bytes)
Bug heat4
Complete LimeSurvey version number (& build)120530
I will donate to the project if issue is resolvedNo
Browser
Database type & versionMysql 5.3
Server OS (if known)Windows XP
Webserver software & version (if known)XAMPP
PHP Version5.3

Relationships

related to 06240 closedTMSWhite conversion of conditions to relevance can fail for multiple choice tests during some upgrades 

Users monitoring this issue

There are no users monitoring this issue.

Activities

TMSWhite

TMSWhite

2012-06-05 17:07

reporter   ~19073

Attached are screen-shots from the EM Unit Test suite showing the current behavior of mathematical comparisons against empty and 0. Green-colored cells have the expected answer. Red-colored cells are errors in that the value differs from what users might expect. Importantly, note that sometimes PHP gives the expected answer and JavaScript does not, and vice-versa.

TMSWhite

TMSWhite

2012-06-05 17:52

reporter   ~19074

emptymath5.jpg shows workable solutions for each of the comparisons of a variable (which might be empty or blank) vs. zero, a constant, or another variable.

Note that the hard one is (var != 0). For the rest, say you have a comparison

var op val

You would change that to:

!is_empty(var) && (var op val)

For (var != 0), you change it to:

is_empty(var) || (var != 0)

TMSWhite

TMSWhite

2012-06-05 18:18

reporter   ~19075

I updated the upgrade hints to clarify how to work-around this situation.

http://docs.limesurvey.org/Upgrade+hints+for+version+1.92#Mathematical_comparisons_against_empty_no_responses

TMSWhite

TMSWhite

2012-06-05 20:34

reporter   ~19076

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

TMSWhite

TMSWhite

2012-06-05 21:10

reporter   ~19077

Fix committed to Yii branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&amp;id=8658

TMSWhite

TMSWhite

2012-06-06 06:10

reporter   ~19078

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

TMSWhite

TMSWhite

2012-06-06 18:23

reporter   ~19084

Fix committed to Yii branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&amp;id=8664

c_schmitz

c_schmitz

2012-06-07 11:02

administrator   ~19097

New 1.91+ build released.

Related Changesets

LimeSurvey: master cc83ee5e

2012-06-05 09:23:17

TMSWhite

Details Diff
Dev Added test cases for issue 06171: variable < X is true even if variable isn't answered Affected Issues
06171
mod - classes/expressions/ExpressionManager.php Diff File

LimeSurvey: Yii 462912a9

2012-06-05 10:48:51

TMSWhite

Details Diff
Dev Added test cases for issue 06171: variable < X is true even if variable isn't answered Affected Issues
06171
mod - application/helpers/expressions/em_core_helper.php Diff File

LimeSurvey: master 6a43810b

2012-06-05 11:33:24

TMSWhite

Details Diff
Fixed issue 06171: variable < X is true even if variable isn't answered
Dev This now works automatically for authors who use the conditions editor
Dev To bulk-convert the entire database, call http://localhost/limesurvey/admin/admin.php?action=EMtest&subaction=upgrade_conditions2relevance
Dev Authors who manually enter relevance equations must pay more attention to the upgrade hints - http://docs.limesurvey.org/Upgrade+hints+for+version+1.92#Mathematical_comparisons_against_empty_no_responses
Affected Issues
06171
mod - classes/expressions/ExpressionManager.php Diff File
mod - classes/expressions/LimeExpressionManager.php Diff File

LimeSurvey: Yii 9a329a94

2012-06-05 12:08:16

TMSWhite

Details Diff
Fixed issue 06171: variable < X is true even if variable isn't answered
Dev This now works automatically for authors who use the conditions editor
Dev To bulk-convert the entire database, call http://localhost/limesurvey/index.php/admin/expressions/upgrade_conditions2relevance
Dev Authors who manually enter relevance equations must pay more attention to the upgrade hints - http://docs.limesurvey.org/Upgrade+hints+for+version+1.92#Mathematical_comparisons_against_empty_no_responses
Affected Issues
06171
mod - application/helpers/expressions/em_core_helper.php Diff File
mod - application/helpers/expressions/em_manager_helper.php Diff File

LimeSurvey: master 8bce8d19

2012-06-05 20:55:40

TMSWhite

Details Diff
Fixed issue 06171: variable < X is true even if variable isn't answered
Dev Now automatically upgrades all conditions in database via database version upgrade
Affected Issues
06171
mod - admin/import_functions.php Diff File
mod - admin/importgroup.php Diff File
mod - admin/importlabel.php Diff File
mod - admin/importquestion.php Diff File
mod - admin/install/cmd_install.php Diff File
mod - admin/update/updater.php Diff File
mod - admin/update/upgrade-mssql.php Diff File
mod - admin/update/upgrade-mssqlnative.php Diff File
mod - admin/update/upgrade-mysql.php Diff File
mod - admin/update/upgrade-postgres.php Diff File
mod - common.php Diff File
mod - version.php Diff File

LimeSurvey: Yii 9e486677

2012-06-06 08:57:41

TMSWhite

Details Diff
Fixed issue 06171: variable < X is true even if variable isn't answered
Dev Now automatically upgrades all conditions in database via database version upgrade
Affected Issues
06171, 06172
mod - application/config/version.php Diff File
mod - application/helpers/update/updatedb_helper.php Diff File

Issue History

Date Modified Username Field Change
2012-06-05 15:16 TMSWhite New Issue
2012-06-05 17:07 TMSWhite Note Added: 19073
2012-06-05 17:07 TMSWhite File Added: emptymath1.jpg
2012-06-05 17:07 TMSWhite File Added: emptymath2.jpg
2012-06-05 17:08 TMSWhite File Added: emptymath3.jpg
2012-06-05 17:26 TMSWhite File Added: emptymath4.jpg
2012-06-05 17:49 TMSWhite File Deleted: emptymath4.jpg
2012-06-05 17:49 TMSWhite File Added: emptymath5.jpg
2012-06-05 17:52 TMSWhite Note Added: 19074
2012-06-05 18:18 TMSWhite Note Added: 19075
2012-06-05 18:25 TMSWhite Changeset attached => LimeSurvey master cc83ee5e
2012-06-05 19:49 TMSWhite Changeset attached => LimeSurvey Yii 462912a9
2012-06-05 20:34 TMSWhite Changeset attached => LimeSurvey master 6a43810b
2012-06-05 20:34 TMSWhite Note Added: 19076
2012-06-05 20:34 TMSWhite Assigned To => TMSWhite
2012-06-05 20:34 TMSWhite Resolution open => fixed
2012-06-05 21:10 TMSWhite Changeset attached => LimeSurvey Yii 9a329a94
2012-06-05 21:10 TMSWhite Note Added: 19077
2012-06-05 21:13 TMSWhite Status new => resolved
2012-06-05 21:13 TMSWhite Fixed in Version => 1.92+
2012-06-06 06:10 TMSWhite Changeset attached => LimeSurvey master 8bce8d19
2012-06-06 06:10 TMSWhite Note Added: 19078
2012-06-06 18:23 TMSWhite Changeset attached => LimeSurvey Yii 9e486677
2012-06-06 18:23 TMSWhite Note Added: 19084
2012-06-07 11:02 c_schmitz Note Added: 19097
2012-06-07 11:02 c_schmitz Status resolved => closed
2012-06-20 16:43 TMSWhite Relationship added related to 06240