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 3cfbae2 commit 5c4e188
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 @@ -5,6 +5,7 @@
- Advanced mail search syntax with more possibilities (without UI) (#8502)
- 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 5c4e188

Please sign in to comment.