Author: vmassol
Date: 2007-09-06 15:21:02 +0200 (Thu, 06 Sep 2007)
New Revision: 4746
Added:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/render/filter/EscapeFilter.java
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/resources/META-INF/services/com.xpn.xwiki.render.filter.XWikiFilter
xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/DefaultXWikiRenderingEngineTest.java
Log:
XWIKI-1705: Single backslashes inside {code} block
Added:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/render/filter/EscapeFilter.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/render/filter/EscapeFilter.java
2007-09-06 13:20:17 UTC (rev 4745)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/render/filter/EscapeFilter.java
2007-09-06 13:21:02 UTC (rev 4746)
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2007, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * This file was initally copied from Radeox. See below for the Radeox license
and
+ * copyright.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ */
+
+/*
+ * This file is part of "SnipSnap Radeox Rendering Engine".
+ *
+ * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
+ * All Rights Reserved.
+ *
+ * Please visit http://radeox.org/ for updates and contact.
+ *
+ * --LICENSE NOTICE--
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * --LICENSE NOTICE--
+ */
+package com.xpn.xwiki.render.filter;
+
+import org.radeox.filter.CacheFilter;
+import org.radeox.filter.context.FilterContext;
+import org.radeox.filter.regex.LocaleRegexTokenFilter;
+import org.radeox.regex.MatchResult;
+import org.radeox.util.Encoder;
+
+/*
+ * Transforms multiple \ into single backspaces and escapes other characters.
+ */
+public class EscapeFilter extends LocaleRegexTokenFilter implements CacheFilter
+{
+ protected String getLocaleKey()
+ {
+ return "filter.escape";
+ }
+
+ public void handleMatch(StringBuffer buffer, MatchResult result,
FilterContext context)
+ {
+ buffer.append(handleMatch(result, context));
+ }
+
+ public String handleMatch(MatchResult result, FilterContext context)
+ {
+ if (result.group(1) == null) {
+ String match = result.group(2);
+ if (match == null) {
+ match = result.group(3);
+ }
+ if ("\\".equals(match)) {
+ return "\\\\";
+ }
+ return Encoder.toEntity(match.charAt(0));
+ } else {
+ return "\";
+ }
+ }
+}
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/resources/META-INF/services/com.xpn.xwiki.render.filter.XWikiFilter
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/resources/META-INF/services/com.xpn.xwiki.render.filter.XWikiFilter
2007-09-06 13:20:17 UTC (rev 4745)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/resources/META-INF/services/com.xpn.xwiki.render.filter.XWikiFilter
2007-09-06 13:21:02 UTC (rev 4746)
@@ -1,6 +1,8 @@
# Remove any content inside the Code macro so that it doesn't get evaluated by
other Radeox macros.
-# The content is restored later on in the CodeRestoreFilter.
+# The content is restored later on in the CodeRestoreFilter. The filter has to
be executed first
+# to ensure no modifications is done to the content.
com.xpn.xwiki.render.filter.CodeRemoveFilter
+com.xpn.xwiki.render.filter.EscapeFilter
org.radeox.filter.ParamFilter
com.xpn.xwiki.render.filter.StyleFilter
com.xpn.xwiki.render.filter.MacroFilter
@@ -25,5 +27,3 @@
com.xpn.xwiki.render.filter.CodeRestoreFilter
# The CodeFilter filter calls the XWikiCodeMacro for performing the rendering
com.xpn.xwiki.render.filter.CodeFilter
-#Should be called first, done with before()
-org.radeox.filter.EscapeFilter
Modified:
xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/DefaultXWikiRenderingEngineTest.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/DefaultXWikiRenderingEngineTest.java
2007-09-06 13:20:17 UTC (rev 4745)
+++
xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/DefaultXWikiRenderingEngineTest.java
2007-09-06 13:21:02 UTC (rev 4746)
@@ -68,6 +68,7 @@
// Last we also ensure that a second code macro works too.
String text = "{code:none}\n"
+ "1 Title\n"
+ + "c:\\dev\n"
+ "#info(\"test\")\n"
+ "<pre>hello</pre>\n"
+ "$xwiki.getVersion()\n"
@@ -84,7 +85,8 @@
+ "{code}";
String expectedText = "<div class=\"code\"><pre>1 Title\n"
- + "#info(\"test\")\n"
+ + "c:\dev\n"
+ + "#info(\"test\")\n"
+ "<pre>hello</pre>\n"
+ "$xwiki.getVersion()\n"
+ "{style}style{style}\n"
_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications