Skip to content

Commit

Permalink
Replace control characters with literal spaces. Resolves #80
Browse files Browse the repository at this point in the history
  • Loading branch information
mmikkel committed Jan 18, 2024
1 parent 794ec88 commit 0b5d154
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/helpers/SEOMateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,27 @@ public static function getPropertyDataByScopeAndHandle(ElementInterface|array $s
}

/**
* Return a meta-safe image asset from raw input
* Return a meta-safe string value from raw input
*
* @param mixed $input
* @return string|null
*/
public static function getStringPropertyValue(mixed $input): ?string
{
$value = trim(strip_tags((string)$input));
if ((bool)$value) {
return $value;
if (empty($input)) {
return null;
}
return null;

$value = (string)$input;

// Replace all control characters with a literal space
$value = preg_replace("/\\x{00a0}/iu", ' ', $value);

// Add literal spaces after linebreak elements and closing paragraph tags, to avoid words being joined together after stripping tags
$value = preg_replace('/((<\/p>|<br( ?)(\/?)>)(?=\S))/iu', '$1 ', $value);

// Strip tags, trim and return
return trim(strip_tags($value)) ?: null;
}

/**
Expand All @@ -243,7 +252,6 @@ public static function getStringPropertyValue(mixed $input): ?string
*/
public static function getImagePropertyValue(mixed $input): ?Asset
{

if (empty($input)) {
return null;
}
Expand Down

0 comments on commit 0b5d154

Please sign in to comment.