Add regex checking for soundcloud links (#874)
* Add regex checking for soundcloud links * Remove outdated test
This commit is contained in:
parent
3a81c82b28
commit
c0099475d7
2 changed files with 3 additions and 13 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue