This is an automated email from the ASF dual-hosted git repository.

nmalin 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 4c32f38267 Fixed: Error viewing entities with fromDate key in entity 
maintenance (OFBIZ-13222)
4c32f38267 is described below

commit 4c32f38267463495ea0c2afc5f15c2398ef0f9e0
Author: Nicolas Malin <nicolas.ma...@nereide.fr>
AuthorDate: Mon Apr 28 18:18:53 2025 +0200

    Fixed: Error viewing entities with fromDate key in entity maintenance 
(OFBIZ-13222)
    
    Viewing entities with a fromDate as a primary seems to be broken with link 
like :
        
https://demo-next.ofbiz.apache.org/webtools/control/entity/find/PartyContactMech/DemoCustomer/9015/2001-05-13%2000:00:00.0
    
    This issue came from exception when we initialize java class java.net.URI 
with it, due to the presence of bad character %20.
    
    To solve it, we encode the entity primary key path to escape this failure.
    
    Thanks to Mickael Brohl for raise this issue and Jacques Leroux for the 
review
---
 .../base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java  | 3 ++-
 .../src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java   | 9 +++++----
 .../main/java/org/apache/ofbiz/webapp/control/ControlFilter.java | 5 ++++-
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git 
a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java 
b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
index 161c07db39..541d750795 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
@@ -183,7 +183,8 @@ public final class UtilHttp {
         String requestURI = req.getRequestURI();
         if (params.isEmpty() && null != requestURI) {
             try {
-                List<NameValuePair> nameValuePairs = URLEncodedUtils.parse(new 
URI(URLDecoder.decode(requestURI, "UTF-8")),
+                List<NameValuePair> nameValuePairs = URLEncodedUtils.parse(
+                        new 
URI(UtilHttp.encodeBlanks(URLDecoder.decode(requestURI, "UTF-8"))),
                         Charset.forName("UTF-8"));
                 for (NameValuePair element : nameValuePairs) {
                     params.put(element.getName(), element.getValue());
diff --git 
a/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java 
b/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java
index 88091a830c..7459658ce6 100644
--- 
a/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java
+++ 
b/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java
@@ -37,6 +37,7 @@ import java.util.Set;
 import java.util.stream.Stream;
 
 import org.apache.ofbiz.base.util.Debug;
+import org.apache.ofbiz.base.util.UtilCodec;
 import org.apache.ofbiz.base.util.UtilDateTime;
 import org.apache.ofbiz.base.util.UtilGenerics;
 import org.apache.ofbiz.base.util.UtilMisc;
@@ -573,7 +574,7 @@ public final class EntityUtil {
     }
 
     /**
-     * For a entityName return the primary keys path that identify it
+     * For a entityName return the primary keys url path that identify it
      * like entityName/pkValue1/pkValue2/../pkValueN
      * @param delegator
      * @param entityName
@@ -585,7 +586,7 @@ public final class EntityUtil {
     }
 
     /**
-     * For a entityName return the primary keys path that identify it
+     * For a entityName return the primary keys url path that identify it
      * like entityName/pkValue1/pkValue2/../pkValueN
      * @param gv
      * @return
@@ -593,7 +594,7 @@ public final class EntityUtil {
     public static String entityToPath(GenericValue gv) {
         StringBuilder path = new StringBuilder(gv.getEntityName());
         for (String pkName : gv.getModelEntity().getPkFieldNames()) {
-            path.append("/").append(gv.getString(pkName));
+            path.append("/").append(UtilCodec.encodeUrl(gv.getString(pkName)));
         }
         return path.toString();
     }
@@ -620,7 +621,7 @@ public final class EntityUtil {
         }
         Map<String, Object> pkValuesMap = new HashMap<>();
         for (String pkName : modelEntity.getPkFieldNames()) {
-            pkValuesMap.put(pkName, pkValues.removeFirst());
+            pkValuesMap.put(pkName, 
UtilCodec.getDecoder("url").decode(pkValues.removeFirst()));
         }
         return pkValuesMap;
     }
diff --git 
a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java
 
b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java
index f5e9a69577..eeb863e3f8 100644
--- 
a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java
+++ 
b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java
@@ -43,6 +43,7 @@ import org.apache.commons.validator.routines.UrlValidator;
 import org.apache.logging.log4j.ThreadContext;
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.StringUtil;
+import org.apache.ofbiz.base.util.UtilHttp;
 import org.apache.ofbiz.base.util.UtilProperties;
 import org.apache.ofbiz.base.util.UtilValidate;
 import org.apache.ofbiz.entity.GenericValue;
@@ -174,7 +175,9 @@ public class ControlFilter extends HttpFilter {
         } else if (req.getAttribute(FORWARDED_FROM_SERVLET) == null
                 && !allowedPaths.isEmpty()) {
             // Get the request URI without the webapp mount point.
-            String uriWithContext = 
StringEscapeUtils.unescapeHtml4(URLDecoder.decode(req.getRequestURI(), 
"UTF-8"));
+            String uriWithContext = UtilHttp.encodeBlanks(
+                    StringEscapeUtils.unescapeHtml4(
+                            URLDecoder.decode(req.getRequestURI(), "UTF-8")));
             String uri = uriWithContext.substring(context.length());
 
 

Reply via email to