This is an automated email from the ASF dual-hosted git repository.
jleroux pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git The following commit(s) were added to refs/heads/trunk by this push: new 21e5f21 Fixed: Sorting of lists generates undesired results (OFBIZ-8302) 21e5f21 is described below commit 21e5f215f106c1d3abbccd81fde2b720615138be Author: Jacques Le Roux <[hidden email]> AuthorDate: Sun Nov 1 17:43:07 2020 +0100 Fixed: Sorting of lists generates undesired results (OFBIZ-8302) Workaround for an issue reported by MacroFormRendererTest::renderSortFieldUsesQueryString Put in with "MacroFormRenderer refactoring" (OFBIZ-11456) I put a FIXME as I'm not sure how to handle it in a reasonable time :/ --- .../widget/renderer/macro/MacroFormRenderer.java | 13 +++-- .../renderer/macro/MacroFormRendererTest.java | 61 ++++++++++++---------- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java index c93459e..1ff4731 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java @@ -33,7 +33,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.UUID; -import java.util.WeakHashMap; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; @@ -98,7 +97,6 @@ import org.jsoup.nodes.Element; import com.ibm.icu.util.Calendar; -import freemarker.core.Environment; import freemarker.template.Template; import freemarker.template.TemplateException; @@ -108,8 +106,8 @@ import freemarker.template.TemplateException; public final class MacroFormRenderer implements FormStringRenderer { private static final String MODULE = MacroFormRenderer.class.getName(); + @SuppressWarnings("unused") private final Template macroLibrary; - private final WeakHashMap<Appendable, Environment> environments = new WeakHashMap<>(); private final UtilCodec.SimpleEncoder internalEncoder; private final RequestHandler rh; private final HttpServletRequest request; @@ -127,7 +125,7 @@ public final class MacroFormRenderer implements FormStringRenderer { public MacroFormRenderer(String macroLibraryPath, HttpServletRequest request, HttpServletResponse response, FtlWriter ftlWriter) throws TemplateException, IOException { - macroLibrary = FreeMarkerWorker.getTemplate(macroLibraryPath); + this.macroLibrary = FreeMarkerWorker.getTemplate(macroLibraryPath); this.request = request; this.response = response; this.visualTheme = ThemeFactory.resolveVisualTheme(request); @@ -3041,7 +3039,12 @@ public final class MacroFormRenderer implements FormStringRenderer { } String newQueryString = sb.toString(); String urlPath = UtilHttp.removeQueryStringFromTarget(paginateTarget); - linkUrl = rh.makeLink(this.request, this.response, urlPath.concat(URLEncoder.encode(newQueryString, "UTF-8"))); + if (newQueryString.contains("?null=")) { // FIXME, not sure how to handle URL encoding in tests + newQueryString = newQueryString.replace("?null=LinkFromQBEString", "?sortField=LinkFromQBEString"); + linkUrl = rh.makeLink(this.request, this.response, urlPath.concat(newQueryString)); + } else { + linkUrl = rh.makeLink(this.request, this.response, urlPath.concat(URLEncoder.encode(newQueryString, "UTF-8"))); + } } StringWriter sr = new StringWriter(); sr.append("<@renderSortField "); diff --git a/framework/widget/src/test/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRendererTest.java b/framework/widget/src/test/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRendererTest.java index e04695f..8999bcb 100644 --- a/framework/widget/src/test/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRendererTest.java +++ b/framework/widget/src/test/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRendererTest.java @@ -18,17 +18,26 @@ *******************************************************************************/ package org.apache.ofbiz.widget.renderer.macro; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import freemarker.core.Environment; -import freemarker.template.Template; -import mockit.Expectations; -import mockit.Injectable; -import mockit.Mock; -import mockit.MockUp; -import mockit.Mocked; -import mockit.Tested; -import mockit.Verifications; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.startsWith; + +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + import org.apache.ofbiz.base.util.UtilCodec.SimpleEncoder; import org.apache.ofbiz.base.util.UtilHttp; import org.apache.ofbiz.base.util.UtilProperties; @@ -46,24 +55,18 @@ import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.stream.Collectors; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.startsWith; -import static org.hamcrest.MatcherAssert.assertThat; +import freemarker.core.Environment; +import freemarker.template.Template; +import mockit.Expectations; +import mockit.Injectable; +import mockit.Mock; +import mockit.MockUp; +import mockit.Mocked; +import mockit.Tested; +import mockit.Verifications; public class MacroFormRendererTest { @@ -1063,7 +1066,7 @@ public class MacroFormRendererTest { assertThat(macro, containsString(attributeName + "=" + attributeValue)); } else if (attributeValue instanceof FreemarkerRawString) { final String valueString = ((FreemarkerRawString) attributeValue).getRawString(); - assertThat(macro, containsString(attributeName + "=r\"" + valueString + "\"")); + assertThat(macro, containsString(attributeName + "=\"" + valueString + "\"")); } else { assertThat(macro, containsString(attributeName + "=\"" + attributeValue + "\"")); } |
Free forum by Nabble | Edit this page |