View Issue Details

This bug affects 1 person(s).
 10
IDProjectCategoryView StatusLast Update
07236Bug reportsExpression Managerpublic2013-02-09 17:34
ReporterDenisChenu Assigned ToDenisChenu  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Product Version2.00+ 
Fixed in Version2.00+ 
Summary07236: Unable to concatenate number : + don't work and join is undefined
Description

EM don't offer possibility to concatenate number

Steps To Reproduce

Try to have : 10€ or $10 with EM

You can import included survey to see the problem.

Additional Information

In EM:
with +:
If the 2 var are string then concatenate : seems OK
If the 2 var can be number : do sum : Think it's not godd, need to test if the 2 var are real number (difference between 10+10 and "10"+"10")
If the 2 var are "different" send NAN ... easy to replace by a concatenate, but still the "10"+"10" issue.

Trying to use {join("A","B")} => show undefined function

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

Users monitoring this issue

TMSWhite

Activities

DenisChenu

DenisChenu

2013-01-27 14:34

developer   ~23831

And for number format, we can using it with another format too.
For example :

number_format ( QCODE , 2 , ',' , ' ' )

c_schmitz

c_schmitz

2013-01-28 11:06

administrator   ~23839

Documentation says to use join(arg1,arg2) for concatenation. Funny enough this function is not in the function list.

DenisChenu

DenisChenu

2013-01-28 11:10

developer   ~23842

Then move to documentation.

Thanks

DenisChenu

DenisChenu

2013-01-28 11:14

developer   ~23843

Problem:
join => undefined function.

DenisChenu

DenisChenu

2013-01-28 11:15

developer   ~23844

Bug updated

c_schmitz

c_schmitz

2013-01-28 12:06

administrator   ~23847

Thomas, any idea on this?

TMSWhite

TMSWhite

2013-01-28 18:32

reporter   ~23849

the missing join() function is an oversight. There is an implode() function that can be used instead.

The root problem is a (perhaps misguided) effort to get + to work identically in PHP and JavaScript. For the equation "a + b", JavaScript treats + as concat() if a is of type String (even if it is numeric). So, ExpressionManager (one of the RDP_xxx() functions) tries to emulate that behavior in PHP.

In retrospect, this may cause more problems than not, so I'd be happy to have + always mean "add" and force users to use join(), or implode() to do concatenation.

So, recommendations are:
(1) Add join() function to EM (or change documentation to have them use implode())
(2) Make "+" always mean add (and never concatenate), and let it throw a NaN exception as needed.

/Tom

DenisChenu

DenisChenu

2013-01-28 19:41

developer   ~23852

Last edited: 2013-01-28 19:42

Think implode are made for array, not to concatenate string.

1st: join(2 var) , see after for 3.... and more

TMSWhite

TMSWhite

2013-01-28 19:50

reporter   ~23853

The EM implode() function does work for contatenating strings (e.g. the function takes an unlimited number of arguments), even if the original PHP implode() function was meant for arrays.

DenisChenu

DenisChenu

2013-01-28 23:07

developer   ~23856

Think some user use + only for addition, sometimes with "10"+"10", then you break their survey.

Maybe:
If $bNumerci : +
else concatenate

And adding join

DenisChenu

DenisChenu

2013-01-28 23:10

developer   ~23857

em_core_helper:
case '+':
if ($bBothNumeric) {
$result = array(($arg1[0] + $arg2[0]),$token[1],'NUMBER');
}
else{
$result = array($arg1[0] . $arg2[0],$token[1],'STRING');
}

TMSWhite

TMSWhite

2013-01-28 23:25

reporter   ~23858

1.92 and 2.0 both already have this code for RDP_EvaluateBinary()

case '+':
if ($bBothNumeric) {
$result = array(($arg1[0] + $arg2[0]),$token[1],'NUMBER');
}
else if ($bBothString) {
$result = array($arg1[0] . $arg2[0],$token[1],'STRING');
} else {
$result = array(NAN,$token[1],'NUMBER');
}
break;

So the problem is likely in em_javascript.js or GetJavaScriptEquivalentOfExpression()

DenisChenu

DenisChenu

2013-01-29 08:03

developer   ~23867

I propose to remove the if ($bBothString) test.

Then if both can be numeric Adding else concatenate.
Don't look at javascript now.

Mazi

Mazi

2013-01-29 23:57

updater   ~23894

From what I can tell from the forums and from other Limesurvey users I have been working with, "+" is used a lot to concatenate strings/messages and you never know how many users make use of it without us ever having noticed them.

Thus, I really wish to not change the way that function is currently used. It might break dozens or hundreds of running surveys.
Instead, better find a code-wise workaround by using some try-catch statements or the like to handle the special cases we are talking about while keeping the current functionality available for our existing users.

Of course, updating the manual and giving some examples when which functions should best be used, does no harm :-)

DenisChenu

DenisChenu

2013-01-30 11:11

developer   ~23896

Last edited: 2013-01-30 11:11

Mazi:
For starting: it's this OK:

{"10"+"10"} : 20
{"$"+"10"} : "$10"
{"A"+"B"} : "AB"

Actually we have
{"10"+"10"} : 20
{"$"+"10"} : NAN
{"A"+"B"} : "AB"

(Adding join function in php and js after)

DenisChenu

DenisChenu

2013-01-31 21:14

developer   ~23927

The second file show behaviour with same group:
No NAN: but is both can be numeric : sum
If not concatenate.

DenisChenu

DenisChenu

2013-01-31 21:20

developer   ~23928

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

DenisChenu

DenisChenu

2013-02-01 10:37

developer   ~23931

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

c_schmitz

c_schmitz

2013-02-07 10:52

administrator   ~23963

New version 2.00 build 120206 released.

DenisChenu

DenisChenu

2013-02-09 17:21

developer   ~24017

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

DenisChenu

DenisChenu

2013-02-09 17:34

developer   ~24018

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

Related Changesets

LimeSurvey: master 911185fb

2013-01-31 20:17:29

DenisChenu

Details Diff
Fixed issue 07236: Different behaviour of + in EM in same group or next group
Dev: Just fix partially, have to add join function to concatenate 2 number
Affected Issues
07236
mod - application/helpers/expressions/em_core_helper.php Diff File

LimeSurvey: master 8167e5ae

2013-02-01 09:34:12

DenisChenu

Details Diff
Fixed issue 07236: Unable to concatenate number : join is undefined
Dev: adding join($arg), alias of implode("",$arg)
Affected Issues
07236
mod - application/helpers/expressions/em_core_helper.php Diff File
mod - scripts/expressions/em_javascript.js Diff File

LimeSurvey: 2.1 586d0ecc

2013-02-09 16:18:28

DenisChenu

Details Diff
Fixed issue 07236: Different behaviour of + in EM in same group or next group
Dev: Just fix partially, have to add join function to concatenate 2 number
Affected Issues
07236
mod - application/helpers/expressions/em_core_helper.php Diff File

LimeSurvey: 2.1 ac112709

2013-02-09 16:31:06

DenisChenu

Details Diff
Fixed issue 07236: Unable to concatenate number : join is undefined
Dev: adding join($arg), alias of implode("",$arg)
Affected Issues
07236
mod - application/helpers/expressions/em_core_helper.php Diff File
mod - scripts/expressions/em_javascript.js Diff File

Issue History

Date Modified Username Field Change
2013-01-27 14:31 DenisChenu New Issue
2013-01-27 14:31 DenisChenu File Added: limesurvey_survey_concatenate.lss
2013-01-27 14:34 DenisChenu Note Added: 23831
2013-01-28 11:06 c_schmitz Note Added: 23839
2013-01-28 11:10 DenisChenu Note Added: 23842
2013-01-28 11:10 DenisChenu Assigned To => DenisChenu
2013-01-28 11:10 DenisChenu Status new => assigned
2013-01-28 11:10 DenisChenu Category Expression Manager => Documentation
2013-01-28 11:14 DenisChenu Note Added: 23843
2013-01-28 11:14 DenisChenu Assigned To DenisChenu =>
2013-01-28 11:14 DenisChenu Status assigned => new
2013-01-28 11:14 DenisChenu Category Documentation => Expression Manager
2013-01-28 11:14 DenisChenu Summary Unable to concatenate number => Unable to concatenate number : + don't work and join is undefined
2013-01-28 11:15 DenisChenu Note Added: 23844
2013-01-28 11:16 DenisChenu Additional Information Updated
2013-01-28 12:06 c_schmitz Issue Monitored: TMSWhite
2013-01-28 12:06 c_schmitz Note Added: 23847
2013-01-28 18:32 TMSWhite Note Added: 23849
2013-01-28 19:41 DenisChenu Note Added: 23852
2013-01-28 19:42 DenisChenu Note Edited: 23852
2013-01-28 19:50 TMSWhite Note Added: 23853
2013-01-28 23:07 DenisChenu Note Added: 23856
2013-01-28 23:10 DenisChenu Note Added: 23857
2013-01-28 23:25 TMSWhite Note Added: 23858
2013-01-29 08:03 DenisChenu Note Added: 23867
2013-01-29 23:57 Mazi Note Added: 23894
2013-01-30 11:11 DenisChenu Note Added: 23896
2013-01-30 11:11 DenisChenu Note Edited: 23896
2013-01-30 11:12 DenisChenu Assigned To => DenisChenu
2013-01-30 11:12 DenisChenu Status new => assigned
2013-01-31 21:13 DenisChenu File Added: limesurvey_survey_concatenate_samegroup.lss
2013-01-31 21:14 DenisChenu Note Added: 23927
2013-01-31 21:20 DenisChenu Changeset attached => LimeSurvey master 911185fb
2013-01-31 21:20 DenisChenu Note Added: 23928
2013-01-31 21:20 DenisChenu Resolution open => fixed
2013-02-01 10:37 DenisChenu Changeset attached => LimeSurvey master 8167e5ae
2013-02-01 10:37 DenisChenu Note Added: 23931
2013-02-01 10:37 DenisChenu Status assigned => resolved
2013-02-01 10:37 DenisChenu Fixed in Version => 2.00+
2013-02-07 10:52 c_schmitz Note Added: 23963
2013-02-07 10:52 c_schmitz Status resolved => closed
2013-02-09 17:21 DenisChenu Changeset attached => LimeSurvey 2.1 586d0ecc
2013-02-09 17:21 DenisChenu Note Added: 24017
2013-02-09 17:34 DenisChenu Changeset attached => LimeSurvey 2.1 ac112709
2013-02-09 17:34 DenisChenu Note Added: 24018
2021-08-04 11:25 guest Bug heat 8 => 10