Skip to content

Commit

Permalink
fix: html entities in hrefs should not trigger noAnchorUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Stewmon committed Dec 4, 2017
1 parent 1dbebe1 commit 912536a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/formatter.js
Expand Up @@ -73,10 +73,10 @@ function formatAnchor(elem, fn, options) {
if (!options.ignoreHref) {
// Get the href, if present
if (elem.attribs && elem.attribs.href) {
href = elem.attribs.href.replace(/^mailto\:/, '');
href = elem.attribs.href.replace(/^mailto:/, '');
}
if (href) {
if ((!options.noAnchorUrl) || (options.noAnchorUrl && href.indexOf('#') === -1)) {
if ((!options.noAnchorUrl) || (options.noAnchorUrl && href[0] !== '#')) {
if (options.linkHrefBaseUrl && href.indexOf('/') === 0) {
href = options.linkHrefBaseUrl + href;
}
Expand Down
10 changes: 10 additions & 0 deletions test/html-to-text.js
Expand Up @@ -195,6 +195,16 @@ describe('html-to-text', function() {
});

describe('a', function () {
it('should decode html attribute entities from href', function () {
var result = htmlToText.fromString('<a href="/foo?a&#x3D;b">test</a>');
expect(result).to.equal('test [/foo?a=b]');
});

it('should strip mailto: from email links', function () {
var result = htmlToText.fromString('<a href="mailto:foo@example.com">email me</a>');
expect(result).to.equal('email me [foo@example.com]');
});

it('should return link with brackets', function () {
var result = htmlToText.fromString('<a href="http://my.link">test</a>');
expect(result).to.equal('test [http://my.link]');
Expand Down

0 comments on commit 912536a

Please sign in to comment.