eZ Community » Forums » Developer » Extract() returns garbage when result...
expandshrink

Extract() returns garbage when result contains special chars

Extract() returns garbage when result contains special chars

Monday 20 April 2015 8:33:10 am - 4 replies

Hi,

I have written the following code

{$user|extract(1,1)}

and $user value is equal to "Håmel". The above code should return "å". But instead it returns a garbage char (�). Please note that, if I echo out {$user} then it correctly displays "Håmel".

 

Would anyone please help me on this?

 

Thanks in advance.

R

Modified on Monday 20 April 2015 8:34:48 am by Rashidul Islam Rana

Monday 20 April 2015 12:31:18 pm

Hello Rashidul,

Welcome to the eZ Community!

I think you have found a bug in eZ Publish! big-smile.gif Emoticon

I did a bunch of testing and found I could solve the bug but it requires a kernel change which you should not do of course.

The problem is the code which powers the extract template operator uses the php function substr instead of mb_substr.

I did a bit of research and found this helpful thread discussing the topic in question: http://stackoverflow.com/questions/12446877/php-is-it-possible-to-correctly-substr-a-utf-8-string

I did testing and these two instances of substr should be replaced with mb_substr:

https://github.com/ezsystems/ezpublish-legacy/blob/master/lib/eztemplate/classes/eztemplatearrayoperator.php#L1295

https://github.com/ezsystems/ezpublish-legacy/blob/master/lib/eztemplate/classes/eztemplatearrayoperator.php#L1302

This one probably needs to be changed too:

https://github.com/ezsystems/ezpublish-legacy/blob/master/lib/eztemplate/classes/eztemplatearrayoperator.php#L1317

I think this bug affects all of the extract based template operators. But this patch once submitted as PR should solve it without issues (since the kernel already sets mb_internal_encoding( 'utf-8' ) by default.

https://github.com/ezsystems/ezpublish-legacy/blob/master/lib/ezi18n/classes/eztextcodec.php#L524

Would you be willing to submit a pull request to the ezpublish-legacy repository patch this bug?

Alternatively you could avoid the bug by creating a custom template operator.

Also you could override the kernel class within an extension (what I would do while waiting for your pull request to be merged) since it's a little faster than creating a custom template operator.

I hope this helps!

Cheers,
Heath

Wednesday 22 April 2015 1:08:00 pm

Hello Rashidul,

I took the time tonight (instead of sleeping) to build a pull request to solve this issue and other similar issues (within the context of other similar operators provided by the same underlying php class).

If you wish for these changes to be merged into the ezpublish repository please show your support by making a comment in the following pull request:

https://github.com/ezsystems/ezpublish-legacy/pull/1162

Here is the PR's issue ticket: https://jira.ez.no/browse/EZP-24292

I hope this helps you and others!

Cheers,
Heath 

Monday 27 April 2015 8:08:08 am

Hi Heath,

 

Thank you very much for your response. I can't appreciate your effort enough. Sorry for being late in reply. I was very busy. And Yeah, above changes does the trick.

 

Thanks again Man

Monday 27 April 2015 9:27:57 am

Hello Rashidul,

Your very welcome! I was happy to be able to help you address your problem.

Thank you for showing your support in the pull request!

I hope this can be reviewed further and merged quickly.

I'll post updates here as the PR progresses.

Cheers,
Heath

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from