Skip to content

Commit

Permalink
Merge pull request #1287 from ChrisBr/fix_tests
Browse files Browse the repository at this point in the history
Fix failing tests and rubocop offences to fix broken master
  • Loading branch information
adrianschroeter committed Oct 21, 2015
2 parents 30bd524 + 4a2518b commit fa4bf52
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 36 deletions.
9 changes: 9 additions & 0 deletions src/api/app/helpers/webui/project_helper.rb
Expand Up @@ -118,4 +118,13 @@ def map_request_state_to_flag(state)
STATE_ICONS[state.to_s] || ''
end

def escape_list(list)
# The input list is not html_safe because it's
# user input which we should never trust!!!
list.map { |p|
"['".html_safe +
escape_javascript(p) +
"']".html_safe
}.join(',').html_safe
end
end
45 changes: 16 additions & 29 deletions src/api/app/helpers/webui/webui_helper.rb
@@ -1,9 +1,7 @@
# vim: sw=2 et

require 'digest/md5'

module Webui::WebuiHelper

include ActionView::Helpers::JavaScriptHelper
include ActionView::Helpers::AssetTagHelper

Expand Down Expand Up @@ -107,20 +105,17 @@ def arch_repo_table_cell(repo, arch, package_name)
result += code
else
result += link_to(code.gsub(/\s/, ' '),
raw_logfile_path(package: package_name,
project: @project.to_s,
arch: arch, repository: repo),
title: link_title, rel: 'nofollow')
raw_logfile_path(package: package_name, project: @project.to_s, arch: arch, repository: repo),
title: link_title, rel: 'nofollow')
end
else
result += link_to(code.gsub(/\s/, ' '),
{ action: :live_build_log,
package: package_name, project: @project.to_s,
arch: arch, controller: 'package', repository: repo
},
{
title: link_title, rel: 'nofollow'
})
{
action: :live_build_log, package: package_name, project: @project.to_s,
arch: arch, controller: 'package', repository: repo
},
{ title: link_title, rel: 'nofollow' }
)
end
result += '</td>'.html_safe
result
Expand Down Expand Up @@ -418,12 +413,13 @@ def user_and_role(user, role = nil, options = {})

printed_name << " as #{role}" if role

# It's necessary to concat icon and $variable and don't use
# string interpolation! Otherwise we get a new string and
# not an ActiveSupport::SafeBuffer
User.current.is_nobody? ?
icon + printed_name :
# It's necessary to concat icon and $variable and don't use string interpolation!
# Otherwise we get a new string and not an ActiveSupport::SafeBuffer
if User.current.is_nobody?
icon + printed_name
else
icon + link_to_if(!opt[:no_link], printed_name, user_show_path(user))
end
end

def package_link(pack, opts = {})
Expand Down Expand Up @@ -543,9 +539,8 @@ def can_register
end

def escape_nested_list(list)
# The input list is not html_safe
# because it's user input which we
# should never trust!!!
# The input list is not html_safe because it's
# user input which we should never trust!!!
list.map { |item|
"['".html_safe +
escape_javascript(item[0]) +
Expand All @@ -554,12 +549,4 @@ def escape_nested_list(list)
"']".html_safe
}.join(",\n").html_safe
end

def escape_list(list)
list.map { |p|
"['".html_safe +
escape_javascript(p) +
"']".html_safe
}.join(',').html_safe
end
end
2 changes: 1 addition & 1 deletion src/api/test/functional/webui/package_controller_test.rb
Expand Up @@ -201,7 +201,7 @@ def test_download_logfile
end
first('.buildstatus').must_have_text 'succeeded'
click_link 'succeeded'
find(:id, 'log_space').must_have_text '[1] this is my dummy logfile -> ümlaut'
find(:id, 'log_space').must_have_text '[1] this is my dummy logfile -&gt; ümlaut'
first(:link, 'Download logfile').click
# don't bother with the ümlaut
assert_match %r{this is my dummy}, page.source
Expand Down
5 changes: 5 additions & 0 deletions src/api/test/unit/webui/project_helper_test.rb
Expand Up @@ -18,4 +18,9 @@ def test_request_state_icon
assert_equal map_request_state_to_flag(nil), ''
end

def test_escape_list_escapes_forbidden_chars
input = ['<p>home:Iggy</p>', '<p>This is a paragraph</p>']
output = "['&lt;p&gt;home:Iggy&lt;\\/p&gt;'],['&lt;p&gt;This is a paragraph&lt;\\/p&gt;']"
assert_equal escape_list(input), output
end
end
6 changes: 0 additions & 6 deletions src/api/test/unit/webui/webui_helper_test.rb
Expand Up @@ -58,12 +58,6 @@ def test_escape_nested_list_escapes_forbidden_chars
assert_equal escape_nested_list(input), output
end

def test_escape_list_escapes_forbidden_chars
input = ['<p>home:Iggy</p>', '<p>This is a paragraph</p>']
output = "['&lt;p&gt;home:Iggy&lt;\\/p&gt;'],['&lt;p&gt;This is a paragraph&lt;\\/p&gt;']"
assert_equal escape_list(input), output
end

def test_format_projectname
assert_equal "some:project:foo:bar", format_projectname("some:project:foo:bar", "bob")
assert_equal "~", format_projectname("home:bob", "bob")
Expand Down

0 comments on commit fa4bf52

Please sign in to comment.