summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-03-14 16:32:55 +0100
committerJulien Lancelot <julien.lancelot@gmail.com>2013-03-14 16:32:55 +0100
commitc45019af11fb385993d0048e02acbc56df1ba793 (patch)
tree48e26bf7dc85d0db86b89ea02ae9cb5f66980a2c
parent56b30607c4a0d8c54222cb29ce49bb429e8a09e3 (diff)
downloadsonarqube-c45019af11fb385993d0048e02acbc56df1ba793.tar.gz
sonarqube-c45019af11fb385993d0048e02acbc56df1ba793.zip
SONAR-4193 Authorize "-" in rule repo and interpret macro when description is not in html
-rw-r--r--sonar-server/src/main/java/org/sonar/server/macro/RuleMacro.java2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/rules/_show.html.erb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/rules/show.html.erb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_note.html.erb2
-rw-r--r--sonar-server/src/test/java/org/sonar/server/ui/MacroInterpreterTest.java9
5 files changed, 13 insertions, 4 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/macro/RuleMacro.java b/sonar-server/src/main/java/org/sonar/server/macro/RuleMacro.java
index 481746c27c0..a88b2bd8b13 100644
--- a/sonar-server/src/main/java/org/sonar/server/macro/RuleMacro.java
+++ b/sonar-server/src/main/java/org/sonar/server/macro/RuleMacro.java
@@ -32,7 +32,7 @@ public class RuleMacro implements Macro{
* First parameter is the repository, second one is the rule key
*/
public String getRegex() {
- return "\\{rule:([a-zA-Z0-9._]++):([a-zA-Z0-9._]++)\\}";
+ return "\\{rule:([a-zA-Z0-9._-]++):([a-zA-Z0-9._]++)\\}";
}
public String getReplacement(){
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules/_show.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules/_show.html.erb
index 4329c732991..ebf1e6f011a 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules/_show.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules/_show.html.erb
@@ -12,7 +12,7 @@
<% if @rule.description.strip.start_with?('<p>') %>
<%= interpret_macro @rule.description %>
<% else %>
- <p><%= @rule.description %></p>
+ <p><%= interpret_macro @rule.description %></p>
<% end %>
<% if @rule.note && !@rule.note.text.strip.blank? %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules/show.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules/show.html.erb
index 1c6a2ed60bd..51482a07c43 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules/show.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules/show.html.erb
@@ -7,7 +7,7 @@
<% if @rule.description.strip.start_with?('<p>') %>
<%= interpret_macro @rule.description %>
<% else %>
- <p><%= @rule.description %></p>
+ <p><%= interpret_macro @rule.description %></p>
<% end %>
<% if @rule.note && !@rule.note.text.strip.blank? %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_note.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_note.html.erb
index e8a28d11f81..1c1723e41b4 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_note.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_note.html.erb
@@ -11,7 +11,7 @@
<% if rule.description.strip.start_with?('<p>') %>
<%= interpret_macro rule.description %>
<% else %>
- <p><%= rule.description %></p>
+ <p><%= interpret_macro rule.description %></p>
<% end %>
<% if note && !note.text.strip.blank? %>
diff --git a/sonar-server/src/test/java/org/sonar/server/ui/MacroInterpreterTest.java b/sonar-server/src/test/java/org/sonar/server/ui/MacroInterpreterTest.java
index 38de7367174..9868a237f8d 100644
--- a/sonar-server/src/test/java/org/sonar/server/ui/MacroInterpreterTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/ui/MacroInterpreterTest.java
@@ -68,4 +68,13 @@ public class MacroInterpreterTest {
String result = interpreter.interpret(origin);
assertThat(result).isEqualTo("See <a class='open-modal rule-modal' href='"+ path + "/rules/show/"+ ruleKey + "?modal=true&layout=false'>" + ruleKey +"</a> for detail.");
}
+
+ @Test
+ public void should_replace_rule_macro_containing_digit_and_dash() {
+ String ruleKey = "my-repo1:key";
+ String origin = "See {rule:"+ ruleKey + "} for detail.";
+ interpreter.start();
+ String result = interpreter.interpret(origin);
+ assertThat(result).isEqualTo("See <a class='open-modal rule-modal' href='"+ path + "/rules/show/"+ ruleKey + "?modal=true&layout=false'>" + ruleKey +"</a> for detail.");
+ }
}