diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-05-04 11:17:02 +0200 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-05-04 11:18:20 +0200 |
commit | 98c661a1e31158b6024bc4339a34b255d643530e (patch) | |
tree | 9222fd67c0332aabb80f8b546ecb230fc49e9157 /sonar-server | |
parent | bf85a1d7e322beb80725c603abc01af646575c0a (diff) | |
download | sonarqube-98c661a1e31158b6024bc4339a34b255d643530e.tar.gz sonarqube-98c661a1e31158b6024bc4339a34b255d643530e.zip |
SONAR-2249 Display Violation message with new lines in web
New method Api::Utils.split_newlines(input) in order to split a string by newlines, whatever the encoding of return carriage.
Diffstat (limited to 'sonar-server')
5 files changed, 17 insertions, 13 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/resource_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/resource_helper.rb index fc4131f6e29..a45515959d5 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/resource_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/resource_helper.rb @@ -19,7 +19,4 @@ # module ResourceHelper - def violation_html_message(violation) - violation.message ? h(violation.message).split(/\r?\n|\r/).join('<br/>') : '' - end end
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb index 2d7ab0cfbfb..5aeb88e1d02 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb @@ -41,4 +41,10 @@ class Api::Utils markdown ? Java::OrgSonarServerUi::JRubyFacade.markdownToHtml(ERB::Util.html_escape(markdown)) : '' end + # splits a string into an array of lines + def self.split_newlines(input) + # Don't limit number of returned fields and don't suppress trailing empty fields by setting second parameter to negative value. + # See http://jira.codehaus.org/browse/SONAR-2282 + input.split(/\r?\n|\r/, -1) + end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb index 9f529d73f80..30615035a46 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb @@ -31,11 +31,18 @@ class RuleFailure < ActiveRecord::Base if message.blank? rule.name else - parts=message.split(/\r?\n|\r/, -1) + parts=Api::Utils.split_newlines(message) parts.size==0 ? rule.name : parts[0] end end end + + def html_message + @html_message ||= + begin + message ? Api::Utils.split_newlines(ERB::Util.html_escape(message)).join('<br/>') : '' + end + end def to_json(include_review=false) json = {} diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot_source.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot_source.rb index 4fa80501405..a6ed3e3c14c 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot_source.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot_source.rb @@ -67,7 +67,7 @@ class SnapshotSource < ActiveRecord::Base end def lines(encode) - SnapshotSource.split_newlines(encoded_data(encode)) + Api::Utils.split_newlines(encoded_data(encode)) end def syntax_highlighted_source @@ -78,13 +78,7 @@ class SnapshotSource < ActiveRecord::Base end def syntax_highlighted_lines - SnapshotSource.split_newlines(syntax_highlighted_source) + Api::Utils.split_newlines(syntax_highlighted_source) end - private - def self.split_newlines(input) - # Don't limit number of returned fields and don't suppress trailing empty fields by setting second parameter to negative value. - # See http://jira.codehaus.org/browse/SONAR-2282 - input.split(/\r?\n|\r/, -1) - end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb index 909f31cb089..3282a0fedee 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb @@ -66,7 +66,7 @@ </div> <div class="discussionComment first"> - <%= h(violation.message) -%> + <%= violation.html_message -%> </div> <% |