Skip to content

Commit

Permalink
TASK: Sanitise labels - Fixes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
jobee committed Jan 3, 2022
1 parent 9de8138 commit 9aadf57
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Classes/DataSource/NodeDataDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ protected function getNodes(NodeInterface $parentNode, $nodeTypes, $labelPropert
}

$label = $labelPropertyName ? $node->getProperty($labelPropertyName) : $node->getLabel();
$label = $this->sanitiseLabel($label);
$groupLabel = $parentNode->getLabel();

if ($setLabelPrefixByNodeContext) {
Expand Down Expand Up @@ -215,4 +216,17 @@ protected function getLabelPrefixByNodeContext(NodeInterface $node, string $labe
$this->labelCache[$nodeHash] = $label;
return $label;
}

/**
* @param string $label
* @return string
*/
protected function sanitiseLabel(string $label)
{
$label = str_replace(' ', ' ', $label);
$label = preg_replace('/<br\\W*?\\/?>|\\x{00a0}|[^[:print:]]|\\s+/u', ' ', $label);
$label = strip_tags($label);
$label = trim($label);
return $label;
}
}

0 comments on commit 9aadf57

Please sign in to comment.