correct case where %20 decoded as space in auto link
correct case where onebox is not applied when url is decoded
This commit is contained in:
parent
340a3ee5cb
commit
d2ba543ed3
|
@ -89,6 +89,12 @@ function renderHoisted(tokens, idx, options) {
|
|||
}
|
||||
}
|
||||
|
||||
function setupUrlDecoding(md) {
|
||||
// this fixed a subtle issue where %20 is decoded as space in
|
||||
// automatic urls
|
||||
md.utils.lib.mdurl.decode.defaultChars = ';/?:@&=+$,# ';
|
||||
}
|
||||
|
||||
function setupHoister(md) {
|
||||
md.renderer.rules.html_raw = renderHoisted;
|
||||
}
|
||||
|
@ -152,6 +158,7 @@ export function setup(opts, siteSettings, state) {
|
|||
typographer: siteSettings.enable_markdown_typographer
|
||||
});
|
||||
|
||||
setupUrlDecoding(opts.engine);
|
||||
setupHoister(opts.engine);
|
||||
setupBlockBBCode(opts.engine);
|
||||
setupInlineBBCode(opts.engine);
|
||||
|
|
|
@ -45,10 +45,7 @@ function applyOnebox(state, silent) {
|
|||
continue;
|
||||
}
|
||||
|
||||
// check text matches href
|
||||
if (text.type !== "text" || attrs[0][1] !== text.content) {
|
||||
continue;
|
||||
}
|
||||
// we already know text matches cause it is an auto link
|
||||
|
||||
if (!close || close.type !== "link_close") {
|
||||
continue;
|
||||
|
|
|
@ -656,7 +656,6 @@ HTML
|
|||
end
|
||||
|
||||
it 'handles onebox correctly' do
|
||||
# we expect 2 oneboxes
|
||||
expect(PrettyText.cook("http://a.com\nhttp://b.com").split("onebox").length).to eq(3)
|
||||
expect(PrettyText.cook("http://a.com\n\nhttp://b.com").split("onebox").length).to eq(3)
|
||||
expect(PrettyText.cook("a\nhttp://a.com")).to include('onebox')
|
||||
|
@ -664,7 +663,6 @@ HTML
|
|||
expect(PrettyText.cook("a\nhttp://a.com a")).not_to include('onebox')
|
||||
expect(PrettyText.cook("a\nhttp://a.com\na")).to include('onebox')
|
||||
expect(PrettyText.cook("http://a.com")).to include('onebox')
|
||||
expect(PrettyText.cook("a.com")).not_to include('onebox')
|
||||
expect(PrettyText.cook("http://a.com ")).to include('onebox')
|
||||
expect(PrettyText.cook("http://a.com a")).not_to include('onebox')
|
||||
expect(PrettyText.cook("- http://a.com")).not_to include('onebox')
|
||||
|
@ -796,6 +794,18 @@ HTML
|
|||
expect(cooked).to eq(html)
|
||||
end
|
||||
|
||||
it "support special handling for space in urls" do
|
||||
cooked = PrettyText.cook "http://testing.com?a%20b"
|
||||
html = '<p><a href="http://testing.com?a%20b" class="onebox" rel="nofollow noopener">http://testing.com?a%20b</a></p>'
|
||||
expect(cooked).to eq(html)
|
||||
end
|
||||
|
||||
it "supports onebox for decoded urls" do
|
||||
cooked = PrettyText.cook "http://testing.com?a%50b"
|
||||
html = '<p><a href="http://testing.com?a%50b" class="onebox" rel="nofollow noopener">http://testing.com?aPb</a></p>'
|
||||
expect(cooked).to eq(html)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue