Skip to content

Commit

Permalink
fix: handle invalid URL
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Sep 1, 2020
1 parent 0abcf7d commit 7628d48
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ class Renderer extends MarkedRenderer {
}
}

let out = `<a href="${encodeURL(href)}"`;
let out = '<a href="';

try {
out += encodeURL(href);
} catch (e) {
out += href;
}

out += '"';

if (title) {
out += ` title="${title}"`;
}
Expand Down
10 changes: 10 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ describe('Marked renderer', () => {
].join('\n'));
});

it('shouldn\'t encode when not a valid URL', () => {
const url = 'http://localhost:4000你好';

const body = `[foo](${url})`;

const result = r({text: body});

result.should.eql(`<p><a href="${url}">foo</a></p>\n`);
});

describe('autolink option tests', () => {
const hexo = new Hexo(__dirname, {silent: true});
const ctx = Object.assign(hexo, {
Expand Down

0 comments on commit 7628d48

Please sign in to comment.