Defect #42233 ยป 42233.patch
lib/redmine/field_format.rb | ||
---|---|---|
130 | 130 |
if value.empty? |
131 | 131 |
value << '' |
132 | 132 |
end |
133 |
elsif custom_field.field_format == 'float' |
|
134 |
value = normalize_float(value) |
|
133 | 135 |
else |
134 | 136 |
value = value.to_s |
135 | 137 |
end |
... | ... | |
540 | 542 |
end |
541 | 543 | |
542 | 544 |
def validate_single_value(custom_field, value, customized=nil) |
543 |
value = normalize_float(value) |
|
544 | 545 |
errs = super |
545 | 546 |
errs << ::I18n.t('activerecord.errors.messages.invalid') unless Kernel.Float(value, exception: false) |
546 | 547 |
errs |
lib/redmine/i18n.rb | ||
---|---|---|
111 | 111 |
# will clash with the dot separator. |
112 | 112 |
def normalize_float(value) |
113 | 113 |
separator = ::I18n.t('number.format.separator') |
114 |
value.gsub(/[#{separator}]/, separator => '.') |
|
114 |
value.to_s.gsub(/[#{separator}]/, separator => '.')
|
|
115 | 115 |
end |
116 | 116 | |
117 | 117 |
def day_name(day) |
test/unit/lib/redmine/field_format/numeric_format_test.rb | ||
---|---|---|
33 | 33 |
assert_equal '<a href="http://foo/3" class="external">3</a>', field.format.formatted_custom_value(self, custom_value, true) |
34 | 34 |
end |
35 | 35 | |
36 |
def test_float_field_value_should_validate_when_given_with_various_separator
|
|
36 |
def test_float_field_should_normalize_decimal_separator
|
|
37 | 37 |
field = IssueCustomField.generate!(field_format: 'float') |
38 | 38 |
issue = Issue.generate!(tracker: Tracker.find(1), status: IssueStatus.find(1), priority: IssuePriority.find(6)) |
39 |
to_test = {'en' => '3.33', 'de' => '3,33'} |
|
40 |
to_test.each do |locale, expected| |
|
41 |
with_locale locale do |
|
42 |
assert field.format.validate_single_value(field, expected, issue) |
|
39 | ||
40 |
with_locale 'de' do |
|
41 |
issue.custom_field_values = { field.id => '3,33' } |
|
42 |
assert issue.save! |
|
43 |
assert_equal '3.33', issue.reload.custom_field_values.last.value |
|
44 |
end |
|
45 | ||
46 |
# Comma decimal separator is not allowed in English locale |
|
47 |
with_locale 'en' do |
|
48 |
issue.custom_field_values = { field.id => '3,33' } |
|
49 |
assert_raise ActiveRecord::RecordInvalid do |
|
50 |
issue.save! |
|
43 | 51 |
end |
44 | 52 |
end |
45 | 53 |
end |