Defect #38464
closedRendering a custom field with a URL pattern set and containing " :" in the value raises Addressable::URI::InvalidURIError
0%
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:
- Field format: Text
- Link values to URL: https://example.com/%value%
- Inside an issue:
- Set the custom field value to:
Test :Test
, i.e.Test
, blank, colon,Test
- Save the issue
- Set the custom field value to:
- 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 issues
Updated by Go MAEDA over 1 year ago
- Related to Defect #32752: Ruby 2.7: Remove deprecated URI.escape/unescape added
Updated by Go MAEDA over 1 year ago
- Status changed from New to Confirmed
- Affected version changed from 5.0.4 to 4.2.0
Updated by Go MAEDA over 1 year ago
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
Updated by Go MAEDA over 1 year ago
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"
Updated by Go MAEDA over 1 year ago
- 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.
Updated by Go MAEDA over 1 year ago
- Target version changed from Candidate for next minor release to 4.2.11
Setting the target version to 4.2.11.
Updated by Go MAEDA over 1 year ago
- 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.
Updated by Go MAEDA over 1 year ago
- Has duplicate Defect #38491: Invalid scheme format: ' VP1' added