From 863a66752b6a1865fb63bbd7b6d4b18c7b07ee99 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Thu, 1 Aug 2024 17:04:33 -0700 Subject: [PATCH] Added better URI validation tests. --- lint/wordlists_yml_spec.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lint/wordlists_yml_spec.rb b/lint/wordlists_yml_spec.rb index f934227..a6c5651 100644 --- a/lint/wordlists_yml_spec.rb +++ b/lint/wordlists_yml_spec.rb @@ -30,8 +30,15 @@ end describe ":url" do - it "must be a http:// or https:// URL" do - expect(attributes[:url]).to match(/\A#{URI::DEFAULT_PARSER.make_regexp(%w[http https])}\z/) + it "must be a valid http:// or https:// URL" do + uri = URI(attributes[:url]) + + expect(uri).to be_kind_of(URI::HTTP).or(be_kind_of(URI::HTTPS)) + expect(uri.host).to_not be(nil), "URI does not have a host name" + expect(uri.host).to_not be_empty, "URI does not have a host name" + expect(uri.port).to_not be(nil), "URI does not have a port number" + expect(uri.path).to_not be(nil), "URI does not have a path" + expect(uri.path).to_not be_empty, "URI does not have a path" end end