Skip to content

Commit 3642626

Browse files
committed
Fixed Stack level too deep error when calling #find_name_by_reflection for missing record.
git-svn-id: http://svn.redmine.org/redmine/trunk@14002 e93f8b46-1217-0410-a6f0-8f06a7374b81
1 parent efbbabe commit 3642626

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

app/helpers/issues_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,14 +460,14 @@ def find_name_by_reflection(field, id)
460460
end
461461
@detail_value_name_by_reflection ||= Hash.new do |hash, key|
462462
association = Issue.reflect_on_association(key.first.to_sym)
463+
name = nil
463464
if association
464465
record = association.klass.find_by_id(key.last)
465466
if record
466-
record.name.force_encoding('UTF-8')
467-
hash[key] = record.name
467+
name = record.name.force_encoding('UTF-8')
468468
end
469469
end
470-
hash[key] ||= nil
470+
hash[key] = name
471471
end
472472
@detail_value_name_by_reflection[[field, id]]
473473
end

test/unit/helpers/issues_helper_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,8 @@ def test_show_detail_relation_deleted_should_not_disclose_issue_that_is_not_visi
295295
assert_equal "Precedes deleted (Issue ##{issue.id})", show_detail(detail, true)
296296
assert_equal "<strong>Precedes</strong> deleted (<i>Issue ##{issue.id}</i>)", show_detail(detail, false)
297297
end
298+
299+
def test_find_name_by_reflection_should_return_nil_for_missing_record
300+
assert_nil find_name_by_reflection('status', 99)
301+
end
298302
end

0 commit comments

Comments
 (0)