Merge pull request #5282 from vinothkannans/local_onebox_slash

FIX: Topic links onebox differently if end in /
This commit is contained in:
Arpit Jalan 2017-11-07 17:39:38 +05:30 committed by GitHub
commit 8f560f0bf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -12,8 +12,7 @@ module Onebox
url = other.to_s
return false unless url[Discourse.base_url]
path = url.sub(Discourse.base_url, "")
route = Rails.application.routes.recognize_path(path)
route = Discourse.route_for(url)
!!(route[:controller] =~ /topics|uploads/)
rescue ActionController::RoutingError
@ -21,8 +20,9 @@ module Onebox
end
def to_html
path = @url.sub(Discourse.base_url, "")
route = Rails.application.routes.recognize_path(path)
uri = URI(@url)
path = uri.path || ""
route = Discourse.route_for(uri)
case route[:controller]
when "uploads" then upload_html(path)

View File

@ -35,6 +35,11 @@ describe Onebox::Engine::DiscourseLocalOnebox do
expect(html).to include(post2.excerpt)
expect(html).to include(post2.topic.title)
url = "#{Discourse.base_url}#{post2.url}/?source_topic_id=#{post2.topic_id + 1}"
html = Onebox.preview(url).to_s
expect(html).to include(post2.excerpt)
expect(html).to include(post2.topic.title)
html = Onebox.preview("#{Discourse.base_url}#{post2.url}").to_s
expect(html).to include(post2.user.username)
expect(html).to include(post2.excerpt)
@ -65,6 +70,10 @@ describe Onebox::Engine::DiscourseLocalOnebox do
html = Onebox.preview(topic.url).to_s
expect(html).to include(topic.ordered_posts.first.user.username)
expect(html).to include("<blockquote>")
html = Onebox.preview("#{topic.url}/?u=codinghorror").to_s
expect(html).to include(topic.ordered_posts.first.user.username)
expect(html).to include("<blockquote>")
end
end