Commit 3992958b authored by Damien McKenna's avatar Damien McKenna Committed by Damien McKenna
Browse files

Issue #3269670 by DamienMcKenna, sd123: Trimming even trims metatags shorter than the limit.

parent 2d6989c1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ Metatag 8.x-1.x-dev, 2022-xx-xx
  Arg #2 ($subject) must be of type string, array given in preg_match_all().
#3258358 by Eugene Bocharov, sashken2, DamienMcKenna, modernrockstar: Empty
  values saved in 'mask_icon' meta tag.
#3269670 by DamienMcKenna, sd123: Trimming even trims metatags shorter than the
  limit.


Metatag 8.x-1.19, 2022-01-06
+6 −0
Original line number Diff line number Diff line
@@ -48,6 +48,12 @@ class MetatagTrimmer {
   *   The trimmed string.
   */
  public function trimBeforeValue($string, $maxlength) {
    // If the string is shorter than the max length then skip the rest of the
    // logic.
    if ($maxlength > strlen($string)) {
      return $string;
    }

    $subString = substr($string, 0, $maxlength + 1);
    if (' ' === substr($subString, -1)) {
      return trim($subString);
+1 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ class MetatagTrimmerTest extends UnitTestCase {
    $this->assertEquals($trimResult3, 'Test');
    $trimResult4 = $this->metatagTrimmer->trimAfterValue('Test 123 123', 10);
    $this->assertEquals('Test 123 123', $trimResult4);
    $trimResult5 = $this->metatagTrimmer->trimBeforeValue('Test 123 123', 20);
    $trimResult5 = $this->metatagTrimmer->trimAfterValue('Test 123 123', 20);
    $this->assertEquals('Test 123 123', $trimResult5);
  }