Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Usage of multibyte character encodings (e.g. cyrillic) leads to mistakes:
Warning: htmlspecialchars() [function.htmlspecialchars]: Invalid multibyte sequence in argument in check_plain()
...
PDOException: in drupal_write_record()
One can solve the problem replacing substr by mb_substr or better (thanks to Viktor) by drupal_substring.
Replace
// Ensure the generated title isn't too long.
$node->title = substr($node->title, 0, 255);
by
// Ensure the generated title isn't too long.
$node->title = drupal_substr($node->title, 0, 255);
Comment | File | Size | Author |
---|---|---|---|
multibyte_substr.patch | 604 bytes | Anonymous (not verified) |
Comments
Comment #1
Darth_Beholder CreditAttribution: Darth_Beholder commentedthank you!
Comment #2
becw CreditAttribution: becw commentedI ran into this same issue where drupal_write_record() throws PDOExceptions because of node titles with multibyte unicode characters that were truncated by substr(). The original patch fixes the issue for me.
Comment #3
drasgardian CreditAttribution: drasgardian commentedPatch fixed the issue here too, thank you! Would love to see this committed.
Comment #4
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedPatch is working as required
Comment #5
gaurav.kapoor CreditAttribution: gaurav.kapoor commentedPatch doesn't apply.
Comment #6
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedthe issue is already fixed now.
truncate_utf8() has been used which is a better option.
Comment #7
gaurav.kapoor CreditAttribution: gaurav.kapoor commentedComment #8
Anonymous (not verified) CreditAttribution: Anonymous commentedHah! It was my first issue/post/patch on d.org. I did not even know what
status
mean and I chose'Patch (to be ported)'
because I wanted to port code to the official build of the module 😂@Darth_Beholder, @becw, @drasgardian thanks for correction status and review!
And of course, big thanks to @anmolgoyal74 and @gaurav.kapoor for taking control of this module and helped to fix this issue via #937086: If title too long, inaccurate title passed around! 🎉
Absolutely true, thanks again!