From 99e537859a813edbcbf4ce94eae69f33f6361e22 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 13 Nov 2020 15:13:37 +0000 Subject: [PATCH] Fix HTML escaping issues with user role icons --- .rubocop_todo.yml | 6 ------ app/helpers/user_roles_helper.rb | 4 +--- app/views/users/show.html.erb | 2 +- test/helpers/user_roles_helper_test.rb | 12 ++++++------ 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 406a13265..c1060cbe2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -172,9 +172,3 @@ Style/FrozenStringLiteralComment: # Configuration parameters: Strict. Style/NumericLiterals: MinDigits: 11 - -# Offense count: 19 -# Cop supports --auto-correct. -Style/StringConcatenation: - Exclude: - - 'test/helpers/user_roles_helper_test.rb' diff --git a/app/helpers/user_roles_helper.rb b/app/helpers/user_roles_helper.rb index 384fb7280..79e7cc012 100644 --- a/app/helpers/user_roles_helper.rb +++ b/app/helpers/user_roles_helper.rb @@ -1,8 +1,6 @@ module UserRolesHelper def role_icons(user) - UserRole::ALL_ROLES.reduce("".html_safe) do |acc, elem| - "#{acc} #{role_icon(user, elem)}" - end + safe_join(UserRole::ALL_ROLES.collect { |role| role_icon(user, role) }.compact, " ") end def role_icon(user, role) diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 440d68874..694f561b2 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -2,7 +2,7 @@
<%= user_image @user %>
-

<%= @user.display_name %><%= role_icons(@user) %>

+

<%= @user.display_name %> <%= role_icons(@user) %>

<% if current_user and @user.id == current_user.id %>