Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions classes/mapworker.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function __construct(
int $group = 0
) {
global $USER;
$svgcode = preg_replace('/(<\!--\[CDATA\[)(.*?)(\]\]-->)/', '<![CDATA[$2]]>', $svgcode);
$svgcode = preg_replace(
'/<text([^>]*)>(?!(<\!\[CDATA\[))(.*?)<\/text>/',
'<text$1><![CDATA[$3]]></text>',
Expand Down
20 changes: 15 additions & 5 deletions classes/svgmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ public function update_text_and_title(string $placeid, string $text, string $add
// the link.
$titlenode = $this->get_element_by_id('title' . $placeid);
if ($titlenode) {
$titlenode->nodeValue = $text . $additionaltitle;
$titlenode->nodeValue = self::escape_content($text . $additionaltitle);
}
// Set the text element for the link.
$textnode = $this->get_element_by_id('text' . $placeid);
if ($textnode) {
$textnode->nodeValue = $text;
$textnode->nodeValue = self::escape_content($text);
}
}

Expand All @@ -245,9 +245,9 @@ public function update_title(string $id, string $text): void {
}
}
if ($titlenode) {
$titlenode->nodeValue = $text;
$titlenode->nodeValue = self::escape_content($text);
} else {
$titlenode = $this->dom->createElementNS('http://www.w3.org/2000/svg', 'title', $text);
$titlenode = $this->dom->createElementNS('http://www.w3.org/2000/svg', 'title', self::escape_content($text));
$node->insertBefore($titlenode, $node->firstChild);
}
}
Expand Down Expand Up @@ -544,10 +544,20 @@ public function replace_cdata(): void {
$this->svgcode = preg_replace_callback(
'/<!\[CDATA\[(.*?)\]\]>/s',
function ($matches) {
return htmlspecialchars($matches[1], ENT_XML1, 'UTF-8', false);
return self::escape_content($matches[1]);
},
$this->svgcode
);
$this->load_dom();
}

/**
* Escapes content for use in XML.
*
* @param string $content
* @return string
*/
public static function escape_content(string $content): string {
return htmlspecialchars($content, ENT_QUOTES | ENT_XML1, 'UTF-8', false);
}
}
Loading