This is an automated email from the ASF dual-hosted git repository.
nmalin pushed a commit to branch release24.09
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/release24.09 by this push:
new 7827f48f33 Fixed: Error viewing entities with fromDate key in entity
maintenance (OFBIZ-13222)
7827f48f33 is described below
commit 7827f48f3317cc185c95bfb01f708e05702edd08
Author: Nicolas Malin <[email protected]>
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 eb8515e2d1..63496286a4 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
@@ -176,7 +176,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 bfbd36ce76..bba17e9b06 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;
@@ -572,7 +573,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
@@ -584,7 +585,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
@@ -592,7 +593,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();
}
@@ -619,7 +620,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 1479cea7b7..ad248ec544 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;
@@ -178,7 +179,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());