Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding issues #12

Open
lbovet opened this issue Dec 17, 2016 · 0 comments
Open

Encoding issues #12

lbovet opened this issue Dec 17, 2016 · 0 comments

Comments

@lbovet
Copy link
Owner

lbovet commented Dec 17, 2016

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);
                 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant