Defect #38464
closed
Rendering a custom field with a URL pattern set and containing " :" in the value raises Addressable::URI::InvalidURIError
Added by Thomas Löber over 1 year ago.
Updated over 1 year ago.
Description
An Addressable::URI::InvalidURIError
occurs in Issues#show
for certain values used to format a URL.
Steps to reproduce:
- Create an issue custom field:
- Inside an issue:
- Set the custom field value to:
Test :Test
, i.e. Test
, blank, colon, Test
- Save the issue
- When the issue is about to be shown, an
Addressable::URI::InvalidURIError
occurs.
The error is caused by the url_from_pattern
method in lib/redmine/field_format.rb
. The issue can be solved by replacing the 5 occurrances of Addressable::URI.encode
with URI.encode_www_form_component
.
>> Addressable::URI.encode "Test :Test"
Traceback (most recent call last):
Addressable::URI::InvalidURIError (Invalid scheme format: 'Test ')
>> URI.encode_www_form_component "Test :Test"
=> "Test+%3ATest"
Best regards,
Thomas
Files
- Related to Defect #32752: Ruby 2.7: Remove deprecated URI.escape/unescape added
- Status changed from New to Confirmed
- Affected version changed from 5.0.4 to 4.2.0
Thank you for suggesting the fix but some tests fail if you simply replace Addressable::URI.encode
with URI.encode_www_form_component
because it encodes space characters as "+". My understanding is that space characters have to be encoded as "%20" in the path part.
Maybe we have to find another approach.
Failure:
Redmine::FieldFormatTest#test_text_field_with_url_pattern_and_value_containing_a_space_should_format_as_link [/path/to/redmine/test/unit/lib/redmine/field_format/field_format_test.rb:90]:
--- expected
+++ actual
@@ -1 +1 @@
-"<a href=\"http://foo/foo%20bar\" class=\"external\">foo bar</a>"
+"<a href=\"http://foo/foo+bar\" class=\"external\">foo bar</a>"
rails test test/unit/lib/redmine/field_format/field_format_test.rb:85
.F
Failure:
Redmine::FieldFormatTest#test_text_field_with_url_pattern_should_encode_values [/path/to/redmine/test/unit/lib/redmine/field_format/field_format_test.rb:106]:
--- expected
+++ actual
@@ -1 +1 @@
-"<a href=\"http://foo/foo%20bar#anchor\" class=\"external\">foo bar</a>"
+"<a href=\"http://foo/foo+bar#anchor\" class=\"external\">foo bar</a>"
rails test test/unit/lib/redmine/field_format/field_format_test.rb:101
The issue can be fixed by using Addressable::URI.encode_component
instead of Addressable::URI.encode
.
irb(main):001:0> Addressable::URI.encode_component "Test :Test"
=> "Test%20:Test"
- File 38464.patch 38464.patch added
- Subject changed from Addressable::URI::InvalidURIError in Issues#show to Rendering a custom field with a URL pattern set and containing " :" in the value raises Addressable::URI::InvalidURIError
- Target version set to Candidate for next minor release
Here is a patch to fix the issue.
- Target version changed from Candidate for next minor release to 4.2.11
Setting the target version to 4.2.11.
- Status changed from Confirmed to Closed
- Assignee set to Go MAEDA
- Resolution set to Fixed
Committed the patch in r22205. Thank you for reporting the issue.
Also available in: Atom
PDF