Commit 8027388d authored by Josianne Hyson's avatar Josianne Hyson

Fix failure with PO translation linter when there are no translations

When the HTML todolist contained a string that had no translations this
method was producing an error as it tried to call `.include?` on a `nil`
object.

Fix this by checking for the presence of translations first.

Caused by: https://gitlab.com/gitlab-org/gitlab/-/issues/217933
Errors appearing in:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/38772
parent 321c4e14
......@@ -106,7 +106,7 @@ module Gitlab
end
def translations_html_allowed?
html_allowed.present? && all_translations.all? do |translation|
msgid_html_allowed? && html_allowed['translations'].present? && all_translations.all? do |translation|
html_allowed['translations'].include?(translation)
end
end
......
......@@ -328,5 +328,13 @@ RSpec.describe Gitlab::I18n::TranslationEntry do
expect(entry.translations_html_allowed?).to be false
end
end
context 'when the todolist only has the msgid' do
let(:html_todo) { { 'plural_id' => nil, 'translations' => nil } }
it 'returns false' do
expect(entry.translations_html_allowed?).to be false
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment