You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by mb...@apache.org on 2021/08/08 21:52:17 UTC
[roller] 03/03: quote $ and \ to not confuse the Matcher.
This is an automated email from the ASF dual-hosted git repository.
mbien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/roller.git
commit f90f714d1a0db34baa7556d04977c7275589a7fe
Author: Michael Bien <mb...@gmail.com>
AuthorDate: Fri Aug 6 17:45:58 2021 +0200
quote $ and \ to not confuse the Matcher.
---
.../roller/weblogger/business/plugins/entry/EncodePreTagsPlugin.java | 2 +-
.../weblogger/business/plugins/entry/EncodePreTagsPluginTest.java | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/app/src/main/java/org/apache/roller/weblogger/business/plugins/entry/EncodePreTagsPlugin.java b/app/src/main/java/org/apache/roller/weblogger/business/plugins/entry/EncodePreTagsPlugin.java
index 2689496..00c8650 100644
--- a/app/src/main/java/org/apache/roller/weblogger/business/plugins/entry/EncodePreTagsPlugin.java
+++ b/app/src/main/java/org/apache/roller/weblogger/business/plugins/entry/EncodePreTagsPlugin.java
@@ -82,7 +82,7 @@ public class EncodePreTagsPlugin implements WeblogEntryPlugin {
// we only have to encode the opening angle bracket for valid html/xhtml
private static String encode(String code_inner) {
- return code_inner.replace("<", LT);
+ return Matcher.quoteReplacement(code_inner.replace("<", LT)); // matchers hate $ and \
}
}
diff --git a/app/src/test/java/org/apache/roller/weblogger/business/plugins/entry/EncodePreTagsPluginTest.java b/app/src/test/java/org/apache/roller/weblogger/business/plugins/entry/EncodePreTagsPluginTest.java
index 4dfbe18..e5861f8 100644
--- a/app/src/test/java/org/apache/roller/weblogger/business/plugins/entry/EncodePreTagsPluginTest.java
+++ b/app/src/test/java/org/apache/roller/weblogger/business/plugins/entry/EncodePreTagsPluginTest.java
@@ -84,6 +84,8 @@ public class EncodePreTagsPluginTest {
" </head>\n" +
" <body>\n" +
" <pre><code class='language-java'>private final Map<String, List<?>> map = new HashMap<>();</code></pre>\n"+
+ " <pre><code class='language-bash'>$JDK/bin/java -version</code></pre>\n"+
+ " <pre><code class='language-slash'>\\\\</code></pre>\n"+
" </body>\n" +
"</html>";
@@ -94,6 +96,8 @@ public class EncodePreTagsPluginTest {
" </head>\n" +
" <body>\n" +
" <pre><code class='language-java'>private final Map<String, List<?>> map = new HashMap<>();</code></pre>\n"+
+ " <pre><code class='language-bash'>$JDK/bin/java -version</code></pre>\n"+
+ " <pre><code class='language-slash'>\\\\</code></pre>\n"+
" </body>\n" +
"</html>";
assertEquals(expected, instance.render(null, input));