diff --git a/lib/open_project/form_tag_helper.rb b/lib/open_project/form_tag_helper.rb
index 803f476935..167bceef53 100644
--- a/lib/open_project/form_tag_helper.rb
+++ b/lib/open_project/form_tag_helper.rb
@@ -59,6 +59,7 @@ module OpenProject
block_given? && content_or_options.is_a?(Hash) ? content_or_options : (options ||= {}),
'form--label'
)
+ options[:title] = strip_tags(options[:title] || capture(&block))
label_tag(name, content_or_options, options, &block)
end
diff --git a/spec/lib/open_project/form_tag_helper_spec.rb b/spec/lib/open_project/form_tag_helper_spec.rb
index c1447f0e19..384dabc7a4 100644
--- a/spec/lib/open_project/form_tag_helper_spec.rb
+++ b/spec/lib/open_project/form_tag_helper_spec.rb
@@ -93,7 +93,30 @@ describe OpenProject::FormTagHelper, type: :helper do
it 'should output element' do
expect(output).to be_html_eql(%{
-
+
+ })
+ end
+
+ it 'should use the title from the options if given' do
+ label = helper.styled_label_tag 'field', 'Lautrec', title: 'Carim'
+ expect(label).to be_html_eql(%{
+
+ })
+ end
+
+ it 'should prefer the title given in the options over the content' do
+ label = helper.styled_label_tag('field', nil, title: 'Carim') { 'Lordvessel' }
+ expect(label).to be_html_eql(%{
+
+ })
+ end
+
+ it 'should strip any given inline HTML from the title tag' do
+ label = helper.styled_label_tag('field') do
+ helper.content_tag :span, 'Sif'
+ end
+ expect(label).to be_html_eql(%{
+
})
end
end