Undefined variable: bytes in String.php line 974
mdarse opened this issue · 8 comments
String::toCode()
is broken when passing a non-breaking space 0xa0
with the following error:
[Symfony\Component\Debug\Exception\ContextErrorException]
Notice: Undefined variable: bytes in /var/www/phraseanet/vendor/hoa/string/String.php line 974
Exception trace:
() at /var/www/phraseanet/vendor/hoa/string/String.php:974
Symfony\Component\Debug\ErrorHandler->handle() at /var/www/phraseanet/vendor/hoa/string/String.php:973
Hoa\String\String::toCode() at /var/www/phraseanet/vendor/hoa/regex/Visitor/Isotropic.php:172
Hoa\Regex\Visitor\Isotropic->visit() at /var/www/phraseanet/vendor/hoa/compiler/Llk/TreeNode.php:336
Hoa\Compiler\Llk\TreeNode->accept() at /var/www/phraseanet/vendor/hoa/regex/Visitor/Isotropic.php:161
Hoa\Regex\Visitor\Isotropic->visit() at /var/www/phraseanet/vendor/hoa/compiler/Llk/TreeNode.php:336
Hoa\Compiler\Llk\TreeNode->accept() at /var/www/phraseanet/vendor/hoa/regex/Visitor/Isotropic.php:97
Hoa\Regex\Visitor\Isotropic->visit() at /var/www/phraseanet/vendor/hoa/compiler/Llk/Sampler/Sampler.php:203
Hoa\Compiler\Llk\Sampler\Sampler->generateToken() at /var/www/phraseanet/vendor/hoa/compiler/Llk/Sampler/BoundedExhaustive.php:184
Hoa\Compiler\Llk\Sampler\BoundedExhaustive->valid() at /var/www/phraseanet/lib/Alchemy/Phrasea/Command/SearchEngine/Debug/QuerySampleCommand.php:63
...
Edit: fixed line 973 to 974 (was due to some editing).
Hello :-),
I am not able to reproduce the bug. I try the following code:
var_dump(Hoa\String::toCode(' '));
/**
* Will output:
* int(160)
*/
where the string contain a non-breaking space.
Are you using the latest version of Hoa\String
? Because on the latest snapshot (the 2.15.02.19), we have nothing at line 973: https://github.com/hoaproject/String/blob/2.15.02.19/String.php#L973.
(I assign @osaris on this one because I am going to be absent for the next few days).
Hi,
After digging the issue, it looks like the issue only occurs with a ANSI non-breaking space 0xa0
but not with UTF-8 one 0xc2a0
.
var_dump(Hoa\String::toCode(chr(160));
/**
* Notice: Undefined variable: bytes in /var/www/phraseanet/vendor/hoa/string/String.php line 974
*/
I don't know if characters in the 128-255 range from latin are supposed to be valid UTF-8 characters or not. I don't know either if Hoa\Compiler\Llk\Sampler\BoundedExhaustive
is supposed to only outputs valid UTF-8 or not.
Mathieu
Hey, thanks for the fix !
Did it solve your issue?
Absolutely!
In fact I did the same fix in a a fork yesterday but didn’t take time to PR it here...
Just updated to your new version and it works perfectly :)
Hope to see a PR next time ;-).