diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/onebox.js.es6 b/app/assets/javascripts/pretty-text/engines/discourse-markdown/onebox.js.es6 index 8681fb729c..2ff5c2a120 100644 --- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/onebox.js.es6 +++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/onebox.js.es6 @@ -4,6 +4,12 @@ import { cachedInlineOnebox } from 'pretty-text/inline-oneboxer'; const ONEBOX = 1; const INLINE = 2; +function isTopLevel(href) { + let split = href.split(/https?:\/\/[^\/]+[\/?]/i); + let hasExtra = split && split[1] && split[1].length > 0; + return !hasExtra; +} + function applyOnebox(state, silent) { if (silent || !state.tokens) { return; @@ -87,17 +93,20 @@ function applyOnebox(state, silent) { attrs.push(["target", "_blank"]); } } else if (mode === INLINE) { - let onebox = cachedInlineOnebox(href); - let options = state.md.options.discourse; - if (options.lookupInlineOnebox) { - onebox = options.lookupInlineOnebox(href); - } + if (!isTopLevel(href)) { + let onebox = cachedInlineOnebox(href); - if (onebox) { - text.content = onebox.title; - } else if (state.md.options.discourse.previewing) { - attrs.push(["class", "inline-onebox-loading"]); + let options = state.md.options.discourse; + if (options.lookupInlineOnebox) { + onebox = options.lookupInlineOnebox(href); + } + + if (onebox) { + text.content = onebox.title; + } else if (state.md.options.discourse.previewing) { + attrs.push(["class", "inline-onebox-loading"]); + } } } diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index 85ddbb955c..73d3a168b3 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -840,15 +840,43 @@ HTML it 'handles mini onebox' do SiteSetting.enable_inline_onebox_on_all_domains = true - InlineOneboxer.purge("http://cnn.com") + InlineOneboxer.purge("http://cnn.com/a") - stub_request(:head, "http://cnn.com").to_return(status: 200) + stub_request(:head, "http://cnn.com/a").to_return(status: 200) - stub_request(:get, "http://cnn.com"). + stub_request(:get, "http://cnn.com/a"). to_return(status: 200, body: "