Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

rescue Addressable::URI::InvalidURIError

Ivan Kuchinb8e7094606ab
diff --git a/app/models/custom_value/link_strategy.rb b/app/models/custom_value/link_strategy.rb
index 091c01de5d6..4c552e06e49 100644
--- a/app/models/custom_value/link_strategy.rb
+++ b/app/models/custom_value/link_strategy.rb
@@ -45,5 +45,7 @@ class CustomValue::LinkStrategy < CustomValue::FormatStrategy
def parsed_url(val)
Addressable::URI.heuristic_parse(val, scheme: "http")
+ rescue Addressable::URI::InvalidURIError
+ nil
end
end
diff --git a/spec/models/custom_value/link_strategy_spec.rb b/spec/models/custom_value/link_strategy_spec.rb
index 5a8c6ee4557..da486161c4b 100644
--- a/spec/models/custom_value/link_strategy_spec.rb
+++ b/spec/models/custom_value/link_strategy_spec.rb
@@ -79,6 +79,12 @@ RSpec.describe CustomValue::LinkStrategy do
it { is_expected.to eq "random:hello" }
end
+ context "when value is just a schema" do
+ let(:value) { "https:" }
+
+ it { is_expected.to eq "https:" }
+ end
+
context "when value is a path" do
let(:value) { "/projects" }
@@ -149,6 +155,12 @@ RSpec.describe CustomValue::LinkStrategy do
it { is_expected.to eq "random:hello" }
end
+ context "when value is just a schema" do
+ let(:value) { "https:" }
+
+ it { is_expected.to eq "https:" }
+ end
+
context "when value is a path" do
let(:value) { "/projects" }
@@ -221,6 +233,12 @@ RSpec.describe CustomValue::LinkStrategy do
it { is_expected.to eq "random:hello" }
end
+ context "when value is just a schema" do
+ let(:input) { "https:" }
+
+ it { is_expected.to be_nil }
+ end
+
context "when value is a path" do
let(:input) { "/projects" }
@@ -291,6 +309,12 @@ RSpec.describe CustomValue::LinkStrategy do
it { is_expected.to be_nil }
end
+ context "when value is just a schema" do
+ let(:value) { "https:" }
+
+ it { is_expected.to eq :invalid_url }
+ end
+
context "when value is a path" do
let(:value) { "/projects" }