Skip to content

Commit

Permalink
Fixed issue #15011: Regular expression - issue - LimeSurvey "removes" 0
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikvitt committed Jul 3, 2019
1 parent 6c6f350 commit 1ce7be1
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions assets/scripts/expressions/em_javascript.js
Expand Up @@ -1044,12 +1044,18 @@ function LEMval(alias)
}
else if(!isNaN(parseFloat(value)) && isFinite(value))
{
// If it's not a decimal number, just return value
try {
var decimal_safe = new Decimal(value);
return Number(decimal_safe.toPrecision(value.length));
var length = value.length;
var firstLetterIsNull = value.split("").shift() === '0';
try{
var numtest = new Decimal(value);
} catch(e){
var numtest = new Decimal(value.toString().replace(/,/,'.'));
}
catch (ex) {
value = numtest.valueOf();
if(value.length < length && firstLetterIsNull){
value = str_repeat('0', length).substr(0,(length - value.length))+''+value.toString(); /* return string as it is */
} else {
value = Number(value); /* If it's a number : always return a number */
}
}

Expand Down

3 comments on commit 1ce7be1

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question : did you check for 0.000100 on a text question ?

Maybe it fix https://bugs.limesurvey.org/view.php?id=15009 too :)

@dominikvitt
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should return value as entered because both conditions are met:

  • it starts with zero
  • length of value converted to number is different than length of entered value
    I'll check it tomorrow.

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's worth …

Capture d’écran du 2019-07-03 16-00-22

It move 0 from end to start … (checked with https://bugs.limesurvey.org/view.php?id=15009 lss)

Please sign in to comment.