Anonymous Login
2016-12-03 05:36 CET

View Issue Details Jump to Notes ] Related Changesets ]
IDProjectCategoryView StatusLast Update
07236Bug reports[All Projects] Expression Managerpublic2013-02-09 17:34
ReporterDenisChenu 
Assigned ToDenisChenu 
PrioritynormalSeverityminor 
StatusclosedResolutionfixed 
Product Version2.00+ 
Target VersionFixed in Version2.00+ 
Summary07236: Unable to concatenate number : + don't work and join is undefined
DescriptionEM don't offer possibility to concatenate number
Steps To ReproduceTry to have : 10€ or $10 with EM

You can import included survey to see the problem.
Additional InformationIn 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.
Complete LimeSurvey version number (& build)130127
I will donate to the project if issue is resolvedNo
Browsernot relevant
Database & DB-Versionnot relevant
Operating System (Server)debian/linux
Webserver software & versionapache
PHP VersionPHP Version 5.3
Attached Files

-Relationships
+Relationships

-Notes

~23831

DenisChenu (developer)

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

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

~23839

c_schmitz (administrator)

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

~23842

DenisChenu (developer)

Then move to documentation.

Thanks

~23843

DenisChenu (developer)

Problem:
join => undefined function.

~23844

DenisChenu (developer)

Bug updated

~23847

c_schmitz (administrator)

Thomas, any idea on this?

~23849

TMSWhite (reporter)

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

~23852

DenisChenu (developer)

Last edited: 2013-01-28 19:42

View 2 revisions

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

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

~23853

TMSWhite (reporter)

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.

~23856

DenisChenu (developer)

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

Maybe:
If $bNumerci : +
else concatenate

And adding join

~23857

DenisChenu (developer)

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');
                }

~23858

TMSWhite (reporter)

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()

~23867

DenisChenu (developer)

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

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

~23894

Mazi (developer)

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 :-)

~23896

DenisChenu (developer)

Last edited: 2013-01-30 11:11

View 2 revisions

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)

~23927

DenisChenu (developer)

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

~23928

DenisChenu (developer)

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

~23931

DenisChenu (developer)

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

~23963

c_schmitz (administrator)

New version 2.00 build 120206 released.

~24017

DenisChenu (developer)

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

~24018

DenisChenu (developer)

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

+Related Changesets

-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 View Revisions
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 View Revisions
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 View Revisions
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
+Issue History