Skip to content

Commit

Permalink
Fix anchor links in HTML mail (#8632)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Jul 30, 2022
1 parent e84d3b7 commit b0186fb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fix various PHP 8.1 warnings (#8628)
- Password: Remove references to %c variable that has been removed before (#8633)
- Fix anchor links in HTML mail (#8632)

## Release 1.6.0

Expand Down
7 changes: 5 additions & 2 deletions program/lib/Roundcube/rcube_washtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,18 @@ private function wash_attribs($node)
$out = $value;
}
}
else if ($this->_css_prefix !== null && in_array($key, ['id', 'class', 'for'])) {
else if ($this->_css_prefix !== null
&& (in_array($key, ['id', 'class', 'for']) || ($key == 'name' && $node->nodeName == 'a'))
) {
$out = preg_replace('/(\S+)/', $this->_css_prefix . '\1', $value);
}
else if ($key) {
$out = $value;
}

if ($out !== null && $out !== '') {
$result .= ' ' . $attr->nodeName . '="' . htmlspecialchars($out, ENT_QUOTES | ENT_SUBSTITUTE, $this->config['charset']) . '"';
$v = htmlspecialchars($out, ENT_QUOTES | ENT_SUBSTITUTE, $this->config['charset']);
$result .= " {$attr->nodeName}=\"{$v}\"";
}
else if ($value) {
$washed[] = htmlspecialchars($attr->nodeName, ENT_QUOTES, $this->config['charset']);
Expand Down
7 changes: 7 additions & 0 deletions tests/Framework/Washtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,13 @@ function test_css_prefix()
$this->assertStringContainsString('for="testmy-other-id"', $washed);
$this->assertStringContainsString('href="#testmy-id"', $washed);
$this->assertStringContainsString('class="testmy-class1 testmy-class2"', $washed);

// Make sure the anchor name is prefixed too
$html = '<p><a href="#a">test link</a></p><a name="a">test anchor</a>';
$washed = $washer->wash($html);

$this->assertStringContainsString('href="#testa"', $washed);
$this->assertStringContainsString('name="testa"', $washed);
}

/**
Expand Down

0 comments on commit b0186fb

Please sign in to comment.