When passing to truncate_utf8() text that spans multiple lines, the function cuts the text on the first newline character if the $wordsafe flag is set to TRUE, no matter what $max_length is passed to it.

To test:

$text = <<

Output:

  • This is a text that spans multiple lines.
  • This is a text that spans multiple lines.
    Line 2 go

Expected behavior:

  • This is a text that spans multiple lines.
    Line 2
  • This is a text that spans multiple lines.
    Line 2 go

The attached patch fixes this by adding the s (PCRE_DOTALL) modifier to the regular expression used.

Files: 
CommentFileSizeAuthor
#9 unicode-truncate-1712106-9-FAIL.patch904 bytesdawehner
FAILED: [[SimpleTest]]: [MySQL] 63,538 pass(es), 2 fail(s), and 0 exception(s). View
#9 unicode-truncate-1712106-9.patch1.77 KBdawehner
PASSED: [[SimpleTest]]: [MySQL] 63,708 pass(es). View
#8 drupal8-cut_on_the_first_line_wordsafe_true-1712106-8.patch913 bytesInternetDevels
PASSED: [[SimpleTest]]: [MySQL] 63,680 pass(es). View

Comments

Feng-Shui’s picture

Attached patched works for me, thanks.

jamix’s picture

Version: 7.x-dev » 8.x-dev
FileSize
814 bytes
PASSED: [[SimpleTest]]: [MySQL] 53,078 pass(es). View

Re-rolling against 8.x-dev.

JacobSanford’s picture

FileSize
913 bytes
PASSED: [[SimpleTest]]: [MySQL] 57,033 pass(es). View

Re-roll to reflect core changes.

gaellafond’s picture

I just found this issue. Any idea when it will be fixed in the Core?

yce’s picture

Thanks, attached patch works for me too. (7.x)

Boobaa’s picture

Issue summary: View changes
FileSize
794 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch truncate_utf8-wordsafe-newlines-1712106-6.patch. Unable to apply patch. See the log in the details link for more information. View

Attached is an updated patch against 7.26 (with offset changes only).

Status: Needs review » Needs work

The last submitted patch, 6: truncate_utf8-wordsafe-newlines-1712106-6.patch, failed testing.

InternetDevels’s picture

Status: Needs work » Needs review
FileSize
913 bytes
PASSED: [[SimpleTest]]: [MySQL] 63,680 pass(es). View

Interdiff is empty, because function truncate_utf8 moved to Unicode::truncate.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
1.77 KB
PASSED: [[SimpleTest]]: [MySQL] 63,708 pass(es). View
904 bytes
FAILED: [[SimpleTest]]: [MySQL] 63,538 pass(es), 2 fail(s), and 0 exception(s). View

The code looked fine, though there was clearly no test so I went ahead and used the issue summary to create one

dawehner’s picture

Status: Reviewed & tested by the community » Needs review

ups

Status: Needs review » Needs work

The last submitted patch, 9: unicode-truncate-1712106-9-FAIL.patch, failed testing.

xmacinfo’s picture

Has this been fixed for Drupal 7?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.