commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kyle Braak (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (OGNL-221) Map with String key that contains a non-word character prevents value from being saved
Date Wed, 15 Aug 2012 14:52:37 GMT

     [ https://issues.apache.org/jira/browse/OGNL-221?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Kyle Braak updated OGNL-221:
----------------------------

    Description: 
I have written a very simple Action, and freemaker template so that you can replicate my problem.


My Action is as follows: 

----------
public class TestAction extends BaseAction {
  private Map<String, String> tmap = new TreeMap<String, String>();

  @Override
  public void prepare() throws Exception {
    super.prepare();
    tmap.put("Animalia", "");
    tmap.put("Ani_malia", "");
    tmap.put("Ani:malia", "");
    tmap.put("Ani-malia", "");
    tmap.put("Ani%malia", "");
    tmap.put("Ani+malia", "");
  }

  @Override
  public String execute() {
    return SUCCESS;
  }

  public Map<String, String> getTmap() {
    return tmap;
  }
}
----------

It prepares a TreeMap with some entries having only a String key, and an empty String value.


The following freemarker template displays the keys, and allows the user to save a new value
for each one:

----------
<form action="test.do" method="post">
<table>
  <tr>
    <td>Key</td>
    <td>Value</td>
  </tr>
  <#list tmap?keys as k>
  <tr>
    <td>${k}</td>
    <td><input type="text" name="tmap['${k}']" value="${tmap.get(k)!}"/></td>
  </tr>
</#list>
</table>
<div>
  <@s.submit name="save"/>
</div>
</form>
----------

Unfortunately, after entering new values for each key and submitting the form, the only keys
that have values successfully saved are: 

Animalia
Ani_malia

The following keys do NOT have values successfully saved:

Ani:malia
Ani-malia
Ani%malia
Ani+malia

Indeed the presence of such non-word characters breaks the OGNL parsing of the Map's String
key. 

To be sure no unwanted interception is occurring, I am using the most basic struts.xml configuration:


----------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
  <package name="ipt-default" extends="struts-default" namespace="/">

    <result-types>
      <result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"
default="true"/>
    </result-types>

    <action name="test" class="org.gbif.ipt.action.portal.TestAction">
      <result>/WEB-INF/pages/portal/test.ftl</result>
    </action>

  </package>
</struts>
----------

Thank you very much for any help you can offer.

With kind regards

  was:
I have written a very simple Action, and freemaker template so that you can replicate my problem.


My Action is as follows: 

{code:title=TestAction.java|borderStyle=solid}
public class TestAction extends BaseAction {
  private Map<String, String> tmap = new TreeMap<String, String>();

  @Override
  public void prepare() throws Exception {
    super.prepare();
    tmap.put("Animalia", "");
    tmap.put("Ani_malia", "");
    tmap.put("Ani:malia", "");
    tmap.put("Ani-malia", "");
    tmap.put("Ani%malia", "");
    tmap.put("Ani+malia", "");
  }

  @Override
  public String execute() {
    return SUCCESS;
  }

  public Map<String, String> getTmap() {
    return tmap;
  }
}
{code} 

It prepares a TreeMap with some entries having only a String key, and an empty String value.


The following freemarker template displays the keys, and allows the user to save a new value
for each one:

{code:title=test.ftl|borderStyle=solid}
<form action="test.do" method="post">
<table>
  <tr>
    <td>Key</td>
    <td>Value</td>
  </tr>
  <#list tmap?keys as k>
  <tr>
    <td>${k}</td>
    <td><input type="text" name="tmap['${k}']" value="${tmap.get(k)!}"/></td>
  </tr>
</#list>
</table>
<div>
  <@s.submit name="save"/>
</div>
</form>
{code} 

Unfortunately, after entering new values for each key and submitting the form, the only keys
that have values successfully saved are: 

Animalia
Ani_malia

The following keys do NOT have values successfully saved:

Ani:malia
Ani-malia
Ani%malia
Ani+malia

Indeed the presence of such non-word characters breaks the OGNL parsing of the Map's String
key. 

To be sure no unwanted interception is occurring, I am using the most basic struts.xml configuration:


{code:xml} 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
  <package name="ipt-default" extends="struts-default" namespace="/">

    <result-types>
      <result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"
default="true"/>
    </result-types>

    <action name="test" class="org.gbif.ipt.action.portal.TestAction">
      <result>/WEB-INF/pages/portal/test.ftl</result>
    </action>

  </package>
</struts>
{code} 

Thank you very much for any help you can offer.

With kind regards

    
> Map with String key that contains a non-word character prevents value from being saved
> --------------------------------------------------------------------------------------
>
>                 Key: OGNL-221
>                 URL: https://issues.apache.org/jira/browse/OGNL-221
>             Project: Commons OGNL
>          Issue Type: Bug
>         Environment: struts2 version 2.2.1 - which uses OGNL 3.0
> freemarker version 2.3.19
>            Reporter: Kyle Braak
>
> I have written a very simple Action, and freemaker template so that you can replicate
my problem. 
> My Action is as follows: 
> ----------
> public class TestAction extends BaseAction {
>   private Map<String, String> tmap = new TreeMap<String, String>();
>   @Override
>   public void prepare() throws Exception {
>     super.prepare();
>     tmap.put("Animalia", "");
>     tmap.put("Ani_malia", "");
>     tmap.put("Ani:malia", "");
>     tmap.put("Ani-malia", "");
>     tmap.put("Ani%malia", "");
>     tmap.put("Ani+malia", "");
>   }
>   @Override
>   public String execute() {
>     return SUCCESS;
>   }
>   public Map<String, String> getTmap() {
>     return tmap;
>   }
> }
> ----------
> It prepares a TreeMap with some entries having only a String key, and an empty String
value. 
> The following freemarker template displays the keys, and allows the user to save a new
value for each one:
> ----------
> <form action="test.do" method="post">
> <table>
>   <tr>
>     <td>Key</td>
>     <td>Value</td>
>   </tr>
>   <#list tmap?keys as k>
>   <tr>
>     <td>${k}</td>
>     <td><input type="text" name="tmap['${k}']" value="${tmap.get(k)!}"/></td>
>   </tr>
> </#list>
> </table>
> <div>
>   <@s.submit name="save"/>
> </div>
> </form>
> ----------
> Unfortunately, after entering new values for each key and submitting the form, the only
keys that have values successfully saved are: 
> Animalia
> Ani_malia
> The following keys do NOT have values successfully saved:
> Ani:malia
> Ani-malia
> Ani%malia
> Ani+malia
> Indeed the presence of such non-word characters breaks the OGNL parsing of the Map's
String key. 
> To be sure no unwanted interception is occurring, I am using the most basic struts.xml
configuration: 
> ----------
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
>   "http://struts.apache.org/dtds/struts-2.0.dtd">
> <struts>
>   <package name="ipt-default" extends="struts-default" namespace="/">
>     <result-types>
>       <result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"
default="true"/>
>     </result-types>
>     <action name="test" class="org.gbif.ipt.action.portal.TestAction">
>       <result>/WEB-INF/pages/portal/test.ftl</result>
>     </action>
>   </package>
> </struts>
> ----------
> Thank you very much for any help you can offer.
> With kind regards

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message