From 84d384a1dcf882eee912033382831968f6949cce Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Mon, 9 May 2016 14:49:51 +0200 Subject: [PATCH] SONAR-6424 Colon character should be escaped in URL (#931) --- .../main/java/org/sonar/server/text/RuleMacro.java | 3 ++- .../org/sonar/server/text/MacroInterpreterTest.java | 13 ++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/text/RuleMacro.java b/server/sonar-server/src/main/java/org/sonar/server/text/RuleMacro.java index a9755c34c6e..93456222514 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/text/RuleMacro.java +++ b/server/sonar-server/src/main/java/org/sonar/server/text/RuleMacro.java @@ -21,6 +21,7 @@ package org.sonar.server.text; class RuleMacro implements Macro { + private static final String COLON = "%3A"; private final String contextPath; RuleMacro(String contextPath) { @@ -37,6 +38,6 @@ class RuleMacro implements Macro { @Override public String getReplacement() { - return "$2"; + return "$2"; } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/text/MacroInterpreterTest.java b/server/sonar-server/src/test/java/org/sonar/server/text/MacroInterpreterTest.java index dbcf65d8fc9..153dbc9dab7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/text/MacroInterpreterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/text/MacroInterpreterTest.java @@ -48,17 +48,12 @@ public class MacroInterpreterTest { @Test public void should_replace_rule_macro() { - String ruleKey = "repo:key"; + // key of repository and rule can contain alphanumeric latin characters, dashes, underscores and dots + String ruleKey = "Some_Repo-Key.1:Some_Rule-Key.1"; String origin = "See {rule:" + ruleKey + "} for detail."; String result = interpreter.interpret(origin); - assertThat(result).isEqualTo("See key for detail."); + // colon should be escaped + assertThat(result).isEqualTo("See Some_Rule-Key.1 for detail."); } - @Test - public void should_replace_rule_macro_containing_digit_and_dash() { - String ruleKey = "my-repo1:my-key1"; - String origin = "See {rule:" + ruleKey + "} for detail."; - String result = interpreter.interpret(origin); - assertThat(result).isEqualTo("See my-key1 for detail."); - } } -- 2.39.5