A platform for community discussion. Free, open, simple.
FEATURE: Handle newer url format for Twitch clips (#31080)
Rafael dos Santos Silva68dde7887a20
diff --git a/lib/onebox/engine/twitch_clips_onebox.rb b/lib/onebox/engine/twitch_clips_onebox.rbindex 022a4e50b2e..3995ec01905 100644--- a/lib/onebox/engine/twitch_clips_onebox.rb+++ b/lib/onebox/engine/twitch_clips_onebox.rb@@ -4,7 +4,7 @@ require_relative "../mixins/twitch_onebox"class Onebox::Engine::TwitchClipsOneboxdef self.twitch_regexp- %r{^https?://clips\.twitch\.tv/([a-zA-Z0-9_]+/?[^#\?/]+)}+ %r{^https?://(?:clips\.twitch\.tv/embed\?clip=|www\.twitch\.tv/[a-zA-Z0-9_]+/clip/|clips\.twitch\.tv/)([a-zA-Z0-9_\-]+)}endinclude Onebox::Mixins::TwitchOneboxdiff --git a/spec/lib/onebox/engine/twitch_clips_onebox_spec.rb b/spec/lib/onebox/engine/twitch_clips_onebox_spec.rbindex a0c620013b2..3d5b57bd130 100644--- a/spec/lib/onebox/engine/twitch_clips_onebox_spec.rb+++ b/spec/lib/onebox/engine/twitch_clips_onebox_spec.rb@@ -3,10 +3,33 @@RSpec.describe Onebox::Engine::TwitchClipsOnebox dolet(:hostname) { Discourse.current_hostname }let(:options) { { hostname: hostname } }+ let(:expected) do+ %r{<iframe src="https://clips\.twitch\.tv/embed\?clip=CheerfulAliveFoxUWot-3FacBI-00c45Ptvd&parent=#{hostname}}+ endit "has the iframe with the correct channel" do- expect(Onebox.preview("https://clips.twitch.tv/FunVastGalagoKlappa", options).to_s).to match(- %r{<iframe src="https://clips\.twitch\.tv/embed\?clip=FunVastGalagoKlappa&parent=#{hostname}},- )+ expect(+ Onebox.preview("https://clips.twitch.tv/CheerfulAliveFoxUWot-3FacBI-00c45Ptvd", options).to_s,+ ).to match(expected)+ end++ it "handles all possible clips urls" do+ expect(+ Onebox.preview(+ "https://www.twitch.tv/gorgc/clip/CheerfulAliveFoxUWot-3FacBI-00c45Ptvd?filter=clips&range=7d&sort=time",+ options,+ ).to_s,+ ).to match(expected)++ expect(+ Onebox.preview(+ "https://clips.twitch.tv/embed?clip=CheerfulAliveFoxUWot-3FacBI-00c45Ptvd&parent=www.example.com",+ options,+ ).to_s,+ ).to match(expected)++ expect(+ Onebox.preview("https://clips.twitch.tv/CheerfulAliveFoxUWot-3FacBI-00c45Ptvd", options).to_s,+ ).to match(expected)endend