Skip to content

Commit

Permalink
Handle all cases of email protection to prevent blinking and ease mai…
Browse files Browse the repository at this point in the history
…ntenance (#959)
  • Loading branch information
Ndpnt authored Dec 13, 2022
2 parents 16e2a71 + cf9487c commit c043d39
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and the format is based on [Common Changelog](https://common-changelog.org).\
Unlike Common Changelog, the `unreleased` section of [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) is preserved with the addition of a tag to specify which type of release should be published and to foster discussions about it inside pull requests. This tag should be one of the names mandated by SemVer, within brackets: `[patch]`, `[minor]` or `[major]`. For example: `## Unreleased [minor]`.

## Unreleased
## Unreleased [minor]

Full changeset and discussions: [#959](https://github.com/ambanum/OpenTermsArchive/pull/959)._

### Changed

- Improved reliability and expanded coverage of email protection global filter

## 0.19.1 - 2022-12-13
### Fixed
Expand Down
9 changes: 6 additions & 3 deletions src/archivist/filter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ export async function filterHTML({ content, pageDeclaration }) {

// clean code from common changing patterns - initially for Windstream
domFragment.querySelectorAll('a[href*="/email-protection"]').forEach(node => {
if (node.href.match(/((.*?)\/email-protection#)[0-9a-fA-F]+/gim)) {
node.href = `${node.href.split('#')[0]}#removed`;
}
const newProtectedLink = webPageDOM.createElement('a');
const [href] = node.href.split('#');

newProtectedLink.href = href;
newProtectedLink.innerHTML = '[email protected]';
node.parentNode.replaceChild(newProtectedLink, node);
});

const markdownContent = transform(domFragment);
Expand Down
5 changes: 4 additions & 1 deletion src/archivist/filter/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const rawHTMLWithCommonChangingItems = `
<p><a id="link3" href="http://absolute.url/link">link 3</a></p>
<p><a id="link4" href="">link 4</a></p>
<a href="/cdn-cgi/l/email-protection#3b4c52555f484f495e5a56154b49524d5a584215484f5a4f5e565e554f7b4c52555f484f495e5a5615585456">[email&#160;protected]</a>
<p><a href="/cdn-cgi/l/email-protection#2d4e4243594c4e596d4e4459545e4e424259034858">conta<span>[email&#160;protected]</span></a></p>
</body>
</html>`;

Expand All @@ -78,7 +79,9 @@ const expectedFilteredWithCommonChangingItems = `Title
link 4
[\\[email protected\\]](https://exemple.com/cdn-cgi/l/email-protection#removed)`;
[\\[email protected\\]](https://exemple.com/cdn-cgi/l/email-protection)
[\\[email protected\\]](https://exemple.com/cdn-cgi/l/email-protection)`;
/* eslint-enable no-irregular-whitespace */

const additionalFilter = {
Expand Down

0 comments on commit c043d39

Please sign in to comment.