From: simonbrandhof Date: Wed, 4 May 2011 09:17:02 +0000 (+0200) Subject: SONAR-2249 Display Violation message with new lines in web X-Git-Tag: 2.8~57 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=98c661a1e31158b6024bc4339a34b255d643530e;p=sonarqube.git 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. --- 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('
') : '' - 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('
') : '' + 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 @@
- <%= h(violation.message) -%> + <%= violation.html_message -%>
<%