Project

General

Profile

Actions

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.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Custom fields
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

An Addressable::URI::InvalidURIError occurs in Issues#show for certain values used to format a URL.

Steps to reproduce:

  1. Create an issue custom field:
  1. Inside an issue:
    • Set the custom field value to: Test :Test, i.e. Test, blank, colon, Test
    • Save the issue
  1. 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

38464.patch (2.81 KB) 38464.patch Go MAEDA, 2023-04-20 12:16

Related issues

Related to Redmine - Defect #32752: Ruby 2.7: Remove deprecated URI.escape/unescapeClosedGo MAEDA

Actions
Has duplicate Redmine - Defect #38491: Invalid scheme format: ' VP1'Closed

Actions
Actions #1

Updated by Go MAEDA over 1 year ago

  • Related to Defect #32752: Ruby 2.7: Remove deprecated URI.escape/unescape added
Actions #2

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
Actions #3

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
Actions #4

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" 
Actions #5

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.

Actions #6

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.

Actions #7

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.

Actions #8

Updated by Go MAEDA over 1 year ago

  • Has duplicate Defect #38491: Invalid scheme format: ' VP1' added
Actions

Also available in: Atom PDF