mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Do not check for duplicate links in Onebox (#13345)
If a user posted a URL that appeared inside a Onebox, then the user got a duplicate link notice. This was fixed by skipping those links in Ruby. If a user posted a URL that was Oneboxes and contained other links that appeared in previous posts, then the user got a duplicate link notice. This was fixed by skipping those links in JavaScript.
This commit is contained in:
parent
74f7295631
commit
1e992d9193
@ -456,7 +456,7 @@ export default Controller.extend({
|
|||||||
$links.each((idx, l) => {
|
$links.each((idx, l) => {
|
||||||
const href = l.href;
|
const href = l.href;
|
||||||
if (href && href.length) {
|
if (href && href.length) {
|
||||||
// skip links in quotes
|
// skip links in quotes and oneboxes
|
||||||
for (let element = l; element; element = element.parentElement) {
|
for (let element = l; element; element = element.parentElement) {
|
||||||
if (
|
if (
|
||||||
element.tagName === "DIV" &&
|
element.tagName === "DIV" &&
|
||||||
@ -471,6 +471,14 @@ export default Controller.extend({
|
|||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
element.tagName === "ASIDE" &&
|
||||||
|
element.classList.contains("onebox") &&
|
||||||
|
href !== element.dataset["onebox-src"]
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const [warn, info] = linkLookup.check(post, href);
|
const [warn, info] = linkLookup.check(post, href);
|
||||||
|
@ -324,8 +324,11 @@ module PrettyText
|
|||||||
links = []
|
links = []
|
||||||
doc = Nokogiri::HTML5.fragment(html)
|
doc = Nokogiri::HTML5.fragment(html)
|
||||||
|
|
||||||
# remove href inside quotes & elided part
|
# extract onebox links
|
||||||
doc.css("aside.quote a, .elided a").each { |a| a["href"] = "" }
|
doc.css("aside.onebox[data-onebox-src]").each { |onebox| links << DetectedLink.new(onebox["data-onebox-src"], false) }
|
||||||
|
|
||||||
|
# remove href inside quotes & oneboxes & elided part
|
||||||
|
doc.css("aside.quote a, aside.onebox a, .elided a").remove
|
||||||
|
|
||||||
# extract all links
|
# extract all links
|
||||||
doc.css("a").each do |a|
|
doc.css("a").each do |a|
|
||||||
|
@ -779,6 +779,22 @@ describe PrettyText do
|
|||||||
].sort)
|
].sort)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should not extract links inside oneboxes" do
|
||||||
|
onebox = <<~EOF
|
||||||
|
<aside class="onebox twitterstatus" data-onebox-src="https://twitter.com/EDBPostgres/status/1402528437441634306">
|
||||||
|
<header class="source">
|
||||||
|
<a href="https://twitter.com/EDBPostgres/status/1402528437441634306" target="_blank" rel="noopener">twitter.com</a>
|
||||||
|
<a href="https://twitter.com/EDBPostgres/status/1402528437441634306" target="_blank" rel="noopener">twitter.com</a>
|
||||||
|
</header>
|
||||||
|
<article class="onebox-body">
|
||||||
|
<div class="tweet">Example URL: <a target="_blank" href="https://example.com" rel="noopener">example.com</a></div>
|
||||||
|
</article>
|
||||||
|
</aside>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
expect(PrettyText.extract_links(onebox).map(&:url)).to contain_exactly("https://twitter.com/EDBPostgres/status/1402528437441634306")
|
||||||
|
end
|
||||||
|
|
||||||
it "should not preserve tags in code blocks" do
|
it "should not preserve tags in code blocks" do
|
||||||
expect(PrettyText.excerpt("<pre><code class='handlebars'><h3>Hours</h3></code></pre>", 100)).to eq("<h3>Hours</h3>")
|
expect(PrettyText.excerpt("<pre><code class='handlebars'><h3>Hours</h3></code></pre>", 100)).to eq("<h3>Hours</h3>")
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user