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

[#56997] file names with + not working

Eric Schubert6c1e066384f0
diff --git a/modules/storages/app/helpers/storages/url_builder.rb b/modules/storages/app/helpers/storages/url_builder.rb
index 41e1d861558..f4ff421918e 100644
--- a/modules/storages/app/helpers/storages/url_builder.rb
+++ b/modules/storages/app/helpers/storages/url_builder.rb
@@ -64,7 +64,14 @@ module Storages
end
def ensure_unescaped_fragments(fragment)
- raise ArgumentError, "URL-escaped character found: #{fragment}" if CGI.unescape(fragment) != fragment
+ raise ArgumentError, "URL-escaped character found: #{fragment}" if improved_unescape(fragment) != fragment
+ end
+
+ def improved_unescape(fragment)
+ # If the fragment contains a '+' character, it will be replaced with its URL-encoded equivalent '%2B' before
+ # decoding. This is because '+' is the only reserved character, that will get replaced by CGI.unescape
+ # (with a whitespace ' ').
+ CGI.unescape(fragment.gsub("+", "%2B"))
end
end
end
diff --git a/modules/storages/spec/common/storages/url_builder_spec.rb b/modules/storages/spec/common/storages/url_builder_spec.rb
index 4a4291194ce..4beaa817f1e 100644
--- a/modules/storages/spec/common/storages/url_builder_spec.rb
+++ b/modules/storages/spec/common/storages/url_builder_spec.rb
@@ -54,8 +54,8 @@ RSpec.describe Storages::UrlBuilder do
expect(described_class.url(storage.uri, "path", "//with-double-slash/"))
.to eq("https://example.com/path/with-double-slash")
- expect(described_class.url(storage.uri, "path", "new folder/stærforge"))
- .to eq("https://example.com/path/new%20folder/st%C3%A6rforge")
+ expect(described_class.url(storage.uri, "path", "new folder/my+stærforge"))
+ .to eq("https://example.com/path/new%20folder/my%2Bst%C3%A6rforge")
end
end