Skip to content

Encoding issues #12

@lbovet

Description

@lbovet

Received once upon a time...
Check if this is still needed.

I got the same issue as listed in 6,7,8,10,15,16 not "able to handle special characters". It needed a small fix that I could figure : Encoding the $ref attribute in JSON response. This is some thing that is already there, but is not working. Below is the existing code. The first two "if clauses" never come true as item is comming an instance of String Class, so I added the url encode in the else clause. It worked for me, but we need to find out in which cases the first two cases will become true.

AbstractTemplateResource.java

if (item instanceof MBeanAttributeInfo)
{
ref.put("$ref", encoderBean.encode(((MBeanAttributeInfo) item).getName()) + "/");
}
else if (item instanceof Map && ((Map) item).containsKey("declaration"))
{
ref.put("$ref", ((Map) item).get("declaration").toString());
}
else
{
ref.put("$ref",encoderBean.encode(item.toString()) + "/"); // This is the fix I added
}

Please find the patch attached and the compiled jar for a quick test.
I think the following defects 6,7,8,10,15,16 are refering to same issue. So all of them can tryout this fix I think

Index: main/java/org/jminix/console/resource/AbstractTemplateResource.java
===================================================================
--- main/java/org/jminix/console/resource/AbstractTemplateResource.java	(revision 103)
+++ main/java/org/jminix/console/resource/AbstractTemplateResource.java	(working copy)
@@ -215,6 +215,8 @@
                     itemCollection = Arrays.asList(items);
                 }
                 List<Map<String, String>> children = new ArrayList<Map<String, String>>();
+                
+                EncoderBean encoderBean = new EncoderBean();
                 for (Object item : itemCollection)
                 {
 
@@ -222,7 +224,7 @@
 
                     if (item instanceof MBeanAttributeInfo)
                     {
-                        ref.put("$ref", new EncoderBean().encode(((MBeanAttributeInfo) item).getName()) + "/");
+                        ref.put("$ref", encoderBean.encode(((MBeanAttributeInfo) item).getName()) + "/");
                     }
                     else if (item instanceof Map && ((Map) item).containsKey("declaration"))
                     {
@@ -230,7 +232,7 @@
                     }
                     else
                     {
-                        ref.put("$ref", item.toString() + "/");
+                	ref.put("$ref",encoderBean.encode(item.toString()) + "/");   
                     }
                     children.add(ref);
                 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions