php-serialize icon indicating copy to clipboard operation
php-serialize copied to clipboard

Not work well for Unicode characters

Open tamvm opened this issue 11 years ago • 2 comments

Thanks for your contribution. I just used your gem and found an issue when working with Unicode characters. Here original serialized string from wordpress:

"a:2:{s:7:\"mau-sac\";a:6:{s:4:\"name\";s:10:\"Màu sắc\";s:5:\"value\";s:4:\"Xanh\";s:8:\"position\";s:1:\"0\";s:10:\"is_visible\";i:1;s:12:\"is_variation\";i:0;s:11:\"is_taxonomy\";i:0;}s:7:\"xuat-xu\";a:6:{s:4:\"name\";s:11:\"Xuất xứ\";s:5:\"value\";s:10:\"Việt Nam\";s:8:\"position\";s:1:\"1\";s:10:\"is_visible\";i:1;s:12:\"is_variation\";i:0;s:11:\"is_taxonomy\";i:0;}}"

Then I used your gem to unserialize and serialize again, and here is the result:

"a:2:{s:7:\"mau-sac\";a:6:{s:4:\"name\";s:10:\"M\xC3\xA0u s\xE1\xBA\xAFc\";s:5:\"value\";s:4:\"Xanh\";s:8:\"position\";s:1:\"0\";s:10:\"is_visible\";i:1;s:12:\"is_variation\";i:0;s:11:\"is_taxonomy\";i:0;}s:7:\"xuat-xu\";a:6:{s:4:\"name\";s:11:\"Xu\xE1\xBA\xA5t x\xE1\xBB\xA9\";s:5:\"value\";s:10:\"Vi\xE1\xBB\x87t Nam\";s:8:\"position\";s:1:\"1\";s:10:\"is_visible\";i:1;s:12:\"is_variation\";i:0;s:11:\"is_taxonomy\";i:0;}}"

It's not the same the original so wordpress can't use them at all.

tamvm avatar Mar 11 '14 20:03 tamvm

It looks like this gem hasn't been maintained for awhile. I've pushed my fork with UTF-8 fixes in the meantime: http://rubygems.org/gems/k-php-serialize

keichan34 avatar Oct 06 '14 15:10 keichan34

Thanks @keichan34

ddarbyson avatar Sep 28 '21 18:09 ddarbyson

This should be fixed via #11 from @keichan34. Released as v1.4.0 today.

> s = "a:2:{s:7:\"mau-sac\";a:6:{s:4:\"name\";s:10:\"Màu sắc\";s:5:\"value\";s:4:\"Xanh\";s:8:\"position\";s:1:\"0\";s:10:\"is_visible\";i:1;s:12:\"is_variation\";i:0;s:11:\"is_taxonomy\";i:0;}s:7:\"xuat-xu\";a:6:{s:4:\"name\";s:11:\"Xuất x
ứ\";s:5:\"value\";s:10:\"Việt Nam\";s:8:\"position\";s:1:\"1\";s:10:\"is_visible\";i:1;s:12:\"is_variation\";i:0;s:11:\"is_taxonomy\";i:0;}}"

> PHP.serialize(PHP.unserialize(s)) == s
true

jqr avatar Feb 24 '24 16:02 jqr

It's nice to see this gem is still being maintained. We heavily rely on it.

ddarbyson avatar Feb 25 '24 17:02 ddarbyson