View Issue Details

This bug affects 1 person(s).
 6
IDProjectCategoryView StatusLast Update
16791Bug reportsExpression Managerpublic2021-03-04 16:41
ReporterMazi Assigned Toollehar  
PrioritynormalSeveritypartial_block 
Status confirmedResolutionopen 
Product Version3.24.3 
Summary16791: strlen() function for counting characters has problems with special characters
DescriptionThe strlen() function acutally counts the byte size of a string, not the number of characters. Since special characters requires more bytes, counting characters using the EM strlen() function leads to wrong results, see attached screenshot or test this demo survey: https://ls300demo.survey-consulting.com/index.php/survey/index/sid/29488/newtest/Y/lang/en

I recommend to NOT replace the strlen() function but keep it for backwards compatibility. Instead, can we add a new mb_strlen() function to EM (see https://www.php.net/manual/de/function.mb-strlen.php)? That should support correct counting of special characters.
Steps To ReproduceImport the attached survey.
Run it and enter some special characters.
Additional Informationsee also https://survey-consulting.com/how-to-count-the-number-of-characters-entered-at-a-limesurvey-text-question/
TagsNo tags attached.
Bug heat6
Complete LimeSurvey version number (& build)Version 3.24
I will donate to the project if issue is resolvedNo
BrowserChrome
Database type & versionMySQL 5
Server OS (if known)Ubuntu 18
Webserver software & version (if known)Apache
PHP Version7.2.26

Users monitoring this issue

User List There are no users monitoring this issue.

Activities

Mazi

Mazi

2020-10-26 15:30

partner  

image.png (22,072 bytes)   
image.png (22,072 bytes)   
Mazi

Mazi

2020-10-26 15:30

partner   ~60414

Last edited: 2020-10-26 15:30

View 2 revisions

@DenisChenu, you fixed a similar problem at the core code base a while ago: https://bugs.limesurvey.org/view.php?id=9785#c32724
ollehar

ollehar

2020-10-26 17:17

administrator   ~60416

multibyte strlen?
DenisChenu

DenisChenu

2020-10-27 10:22

developer   ~60417

2015-07-21 11:21 … yes a while ago …

And seems i update strlmen to use mb_strlen : https://github.com/LimeSurvey/LimeSurvey/commit/c031c7d24d1fecf21dc970e8bccb38eb4abe0a9f#diff-a974f1aca3b64170e04f9ac415aadb10d9108696f0ae4ce07caee89d8a1447d3R2570

seems currently too : https://github.com/LimeSurvey/LimeSurvey/blob/70507e27f6d1886bb50d52d3833284450639c684/application/helpers/expressions/em_core_helper.php#L2678
DenisChenu

DenisChenu

2020-10-27 10:28

developer   ~60418

Last edited: 2020-10-27 10:33

View 2 revisions

<s>JS function need to be fixed/updated BUT</s>

locutus/phpjs didn't have mb_strlen

And the only fix seem : https://stackoverflow.com/questions/2482907/javascript-string-length-differs-from-php-mb-strlen :/

In act : js.length are already mb_strlen …
DenisChenu

DenisChenu

2020-10-27 10:32

developer   ~60419

Someone broke this in 3.X or 2.50x

Working in 2.6lts :

It's not the 1st time something broken in javascript expression … between 2.6lts and 2.5X
Mazi

Mazi

2020-10-27 10:35

partner   ~60420

Interesting that this worked before. So probably all we need to do is finding out which commit caused the problem and then revert to the previous code/function?!
DenisChenu

DenisChenu

2020-10-27 10:36

developer   ~60421

Surely in LEMval …
DenisChenu

DenisChenu

2020-10-27 10:42

developer   ~60422

https://github.com/LimeSurvey/LimeSurvey/blob/70507e27f6d1886bb50d52d3833284450639c684/assets/packages/expressions/em_javascript.js#L1169
https://github.com/SondagesPro/LimeSurvey-SondagesPro/blob/bf34293e9538dba87e4ba9e7968190245c5714ed/scripts/expressions/em_javascript.js#L739
ollehar

ollehar

2021-03-03 16:00

administrator   ~62683

Please check if this bug still exists in the latest patch release. Thank you.
Mazi

Mazi

2021-03-03 18:31

partner   ~62702

@ollehar, why don't you simply import the atteched test survey and test. That only takes a minute.

I just did that and yes, this issue still exists, see https://ls3.my-survey.host/index.php/29488?newtest=Y&lang=en
ollehar

ollehar

2021-03-04 16:36

administrator   ~62716

> @ollehar, why don't you simply import the atteched test survey and test. That only takes a minute.

Classic Mazi. ^^

Because we have hundreds of tickets. It's more efficient if I spread out the testing. Obviously.
ollehar

ollehar

2021-03-04 16:37

administrator   ~62717

> I just did that and yes, this issue still exists, see https://ls3.my-survey.host/index.php/29488?newtest=Y&lang=en

Thanks! We'll look at this issue.

Issue History

Date Modified Username Field Change
2020-10-26 15:30 Mazi New Issue
2020-10-26 15:30 Mazi File Added: image.png
2020-10-26 15:30 Mazi File Added: limesurvey_survey_29488.lss
2020-10-26 15:30 Mazi Note Added: 60414
2020-10-26 15:30 Mazi Note Edited: 60414 View Revisions
2020-10-26 17:17 ollehar Note Added: 60416
2020-10-27 10:22 DenisChenu Note Added: 60417
2020-10-27 10:28 DenisChenu Note Added: 60418
2020-10-27 10:32 DenisChenu Note Added: 60419
2020-10-27 10:32 DenisChenu File Added: Capture d’écran du 2020-10-27 10-31-25.png
2020-10-27 10:33 DenisChenu Note Edited: 60418 View Revisions
2020-10-27 10:35 Mazi Note Added: 60420
2020-10-27 10:36 DenisChenu Note Added: 60421
2020-10-27 10:42 DenisChenu Note Added: 60422
2021-03-03 16:00 ollehar Assigned To => ollehar
2021-03-03 16:00 ollehar Status new => feedback
2021-03-03 16:00 ollehar Note Added: 62683
2021-03-03 18:31 Mazi Note Added: 62702
2021-03-03 18:31 Mazi Status feedback => assigned
2021-03-04 16:36 ollehar Note Added: 62716
2021-03-04 16:37 ollehar Note Added: 62717
2021-03-04 16:37 ollehar Priority none => normal
2021-03-04 16:37 ollehar Description Updated View Revisions
2021-03-04 16:37 ollehar Steps to Reproduce Updated View Revisions
2021-03-04 16:41 ollehar Status assigned => confirmed
2021-03-04 16:41 ollehar Severity block => partial_block