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);
CommentFileSizeAuthor
multibyte_substr.patch604 bytesAnonymous (not verified)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Darth_Beholder’s picture

Issue summary: View changes

thank you!

becw’s picture

Status: Patch (to be ported) » Reviewed & tested by the community

I 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.

drasgardian’s picture

Patch fixed the issue here too, thank you! Would love to see this committed.

anmolgoyal74’s picture

Assigned: Unassigned » anmolgoyal74

Patch is working as required

gaurav.kapoor’s picture

Status: Reviewed & tested by the community » Needs work

Patch doesn't apply.

anmolgoyal74’s picture

Status: Needs work » Needs review

the issue is already fixed now.
truncate_utf8() has been used which is a better option.

gaurav.kapoor’s picture

Status: Needs review » Closed (outdated)
Anonymous’s picture

Status: Closed (outdated) » Closed (duplicate)
Related issues: +#937086: If title too long, inaccurate title passed around

Hah! 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!