Add regex checking for soundcloud links (#874)

* Add regex checking for soundcloud links

* Remove outdated test
This commit is contained in:
Andy Zhao 2018-10-09 15:09:45 -04:00 committed by Mac Siri
parent 3a81c82b28
commit c0099475d7
2 changed files with 3 additions and 13 deletions

View file

@ -35,11 +35,12 @@ class SoundcloudTag < LiquidTagBase
end
def valid_link?(link)
link.include?("soundcloud.com")
(link =~ /\Ahttps:\/\/soundcloud\.com\/([a-zA-Z0-9\_\-]){3,25}\/(sets\/)?([a-zA-Z0-9\_\-]){3,255}\Z/)&.
zero?
end
def raise_error
raise StandardError, "Invalid Soundcloud URL"
raise StandardError, "Invalid Soundcloud URL - try taking off any URL params: '?something=value'"
end
end

View file

@ -4,7 +4,6 @@ require "nokogiri"
RSpec.describe SoundcloudTag, type: :liquid_template do
describe "#link" do
let(:soundcloud_link) { "https://soundcloud.com/user-261265215/dev-to-review-episode-2" }
let(:evil_string) { "<SCRIPT SRC=//xss.rocks/.j>soundcloud.com</SCRIPT>" }
let(:url_segment) { "https://w.soundcloud.com/player/?url" }
def generate_new_liquid(link)
@ -29,15 +28,5 @@ RSpec.describe SoundcloudTag, type: :liquid_template do
generate_new_liquid("invalid_soundcloud_link")
end.to raise_error(StandardError)
end
it "strips script input" do
allow(ActionController::Base.helpers).to receive(:strip_tags).and_return(evil_string)
liquid = generate_new_liquid(evil_string)
rendered_soundcloud_iframe = liquid.render
iframe_src = extract_iframe_src(rendered_soundcloud_iframe)
expect(iframe_src[url_segment]).not_to include("<SCRIPT SRC=//xss.rocks/.j>")
end
end
end