You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2021/03/07 15:24:55 UTC

[ofbiz-framework] branch trunk updated: Improved: Improves encoding in 3 classes

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 8243d92  Improved: Improves encoding in 3 classes
8243d92 is described below

commit 8243d926d0b8c56fbffc3fb93d639d0d843465e8
Author: Jacques Le Roux <ja...@les7arts.com>
AuthorDate: Sun Mar 7 16:23:21 2021 +0100

    Improved: Improves encoding in 3 classes
    
    Fixes an issue put in with commit c54dced51c92e511d8112546e7117fdfe4c6f652
    
    There I wrongly replaced internalEncoder in MacroFormRenderer.java by
    context.get("simpleEncoder")
    
    While at it uses the pattern used in commit cb9c366 in every place in
    modelFormField class
---
 .../apache/ofbiz/widget/model/ModelFormField.java   | 21 ++++++++++++++++++---
 .../widget/renderer/macro/MacroFormRenderer.java    |  2 +-
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java
index 69033d6..c887d79 100644
--- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java
+++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java
@@ -713,7 +713,12 @@ public final class ModelFormField {
             tooltipString = tooltip.expandString(context);
         }
         if (this.getEncodeOutput()) {
-            UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder");
+            UtilCodec.SimpleEncoder simpleEncoder = null;
+            if (tooltipString.equals(StringEscapeUtils.unescapeEcmaScript(StringEscapeUtils.unescapeHtml4(tooltipString)))) {
+                simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder");
+            } else {
+                simpleEncoder = UtilCodec.getEncoder("string");
+            }
             if (simpleEncoder != null) {
                 tooltipString = simpleEncoder.encode(tooltipString);
             }
@@ -1825,7 +1830,12 @@ public final class ModelFormField {
                 }
             }
             if (UtilValidate.isNotEmpty(this.description) && retVal != null && this.getModelFormField().getEncodeOutput()) {
-                UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder");
+                UtilCodec.SimpleEncoder simpleEncoder = null;
+                if (retVal.equals(StringEscapeUtils.unescapeEcmaScript(StringEscapeUtils.unescapeHtml4(retVal)))) {
+                    simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder");
+                } else {
+                    simpleEncoder = UtilCodec.getEncoder("string");
+                }
                 if (simpleEncoder != null) {
                     retVal = simpleEncoder.encode(retVal);
                 }
@@ -2751,7 +2761,12 @@ public final class ModelFormField {
         public String getValue(Map<String, Object> context) {
             if (UtilValidate.isNotEmpty(this.value)) {
                 String valueEnc = this.value.expandString(context);
-                UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder");
+                UtilCodec.SimpleEncoder simpleEncoder = null;
+                if (valueEnc.equals(StringEscapeUtils.unescapeEcmaScript(StringEscapeUtils.unescapeHtml4(valueEnc)))) {
+                    simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder");
+                } else {
+                    simpleEncoder = UtilCodec.getEncoder("string");
+                }
                 if (simpleEncoder != null) {
                     valueEnc = simpleEncoder.encode(valueEnc);
                 }
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 17c4997..2e0e5af 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
@@ -2915,7 +2915,7 @@ public final class MacroFormRenderer implements FormStringRenderer {
         UtilCodec.SimpleEncoder simpleEncoder = null;
         String encodedDescription = null;
         if (description.equals(StringEscapeUtils.unescapeEcmaScript(StringEscapeUtils.unescapeHtml4(description)))) {
-            simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder");
+            simpleEncoder = internalEncoder;
         } else {
             simpleEncoder = UtilCodec.getEncoder("string");
         }