struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Gainty (JIRA)" <j...@apache.org>
Subject [jira] Commented: (WW-3095) URL has no setEncoding
Date Fri, 29 May 2009 17:14:42 GMT

    [ https://issues.apache.org/struts/browse/WW-3095?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46271#action_46271
] 

Martin Gainty commented on WW-3095:
-----------------------------------

you're definitely on the right track

org.apache.struts2.views.util.UrlHelper contains the translateAndEncode method

  /*** Translates any script expressions using {@link com.opensymphony.xwork2.util.TextParseUtil#translateVariables}
and
     * encodes the URL using {@link java.net.URLEncoder#encode} with the encoding specified
in the configuration.
     * @param input
     * @return the translated and encoded string
     */
    public static String translateAndEncode(String input) {
//resolve any stack variables e.g. #attr.variable from ValueStack
        String translatedInput = translateVariable(input);

//always UTF-8
        String encoding = getEncodingFromConfiguration();

        try {
//this is where the REAL encoding takes place
            return URLEncoder.encode(translatedInput, encoding);
        } catch (UnsupportedEncodingException e) {
            LOG.warn("Could not encode URL parameter '" + input + "', returning value un-encoded");
            return translatedInput;
        }
    }

//org.apache.struts2.views.util.UrlHelper contains the translateAndDecode method
    public static String translateAndDecode(String input) {
//resolve any #StackVars
        String translatedInput = translateVariable(input);
//always UTF-8
        String encoding = getEncodingFromConfiguration();

        try 
        {
            return URLDecoder.decode(translatedInput, encoding);
        } 
        catch (UnsupportedEncodingException e) 
        {
            LOG.warn("Could not encode URL parameter '" + input + "', returning value un-encoded");
            return translatedInput;
        }
    }

//and the translateVariable method
    private static String translateVariable(String input) {
        ValueStack valueStack = ServletActionContext.getContext().getValueStack();
        String output = TextParseUtil.translateVariables(input, valueStack);
        return output;
    }
//this only returns UTF-8 
    private static String getEncodingFromConfiguration() {
        final String encoding;
        // FIXME: temporary hack until class is made a properly injected bean
        Container cont = ActionContext.getContext().getContainer();

        String customEncoding = cont.getInstance(String.class, StrutsConstants.STRUTS_I18N_ENCODING);
//  public static final String STRUTS_I18N_ENCODING = "struts.i18n.encoding";
//struts.properties contains
//struts.i18n.encoding=UTF-8

        if (customEncoding != null) {
            encoding = customEncoding;
        } else {
            encoding = "UTF-8";
        }
//FYI: there is no decision or configuration ability as you always return "UTF-8"
        return encoding; //always UTF-8
    }

//but then again calling java.net.UrlEncoder.encode(string,"UTF-8") would return 'supported
code'
public static String encode(String s,String enc) throws UnsupportedEncodingException

//    Translates a string into application/x-www-form-urlencoded format using a specific encoding
scheme. //This method uses the supplied encoding scheme to obtain the bytes for unsafe characters.
//   Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used.
Not doing //so may introduce incompatibilites.
//    Parameters:
//        s - String to be translated.
//        enc - The name of a supported character encoding. 
//    Returns:
//        the translated String. 
//    Throws:
//        UnsupportedEncodingException - If the named encoding is not supported
//    Since:
//        1.4

concerning allowable characters ..here is what I gleaned from http://www.w3.org/Addressing/URL/url-spec.txt
spec:

hostname                ialpha [  .  hostname ] 

//  checking ialpha definition
ialpha                  alpha [ xalphas ]   

//checking alpha definition
  alpha  a | b | c | d | e | f | g | h | i | j | k | l | m | n | o  | p | q | r | s | t |
u | v | w | x | y | z | A | B | C  | D | E | F | G | H | I | J | K | L | M | N | O | P | 
Q | R | S | T | U | V | W | X | Y | Z   
//essentially      [a-z][A-Z]

//checking xalphas definition
  xalphas                 xalpha [ xalphas ]   

//check xalphas definition
  xalpha                  alpha | digit | safe | extra | escape   

//checking alpha [a-z][A-Z] (see above)

//checking digit
digit                   0 |1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9   

//checking safe
safe                    $ | - | _ | @ | . | &  | + | - 

//checking extra
extra                  ! | * |  " |  ' | ( | )  | , 

//checking escape
escape                  % hex hex   

//does this conform to your understanding?

> URL has no setEncoding
> ----------------------
>
>                 Key: WW-3095
>                 URL: https://issues.apache.org/struts/browse/WW-3095
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Plugin - Tags
>    Affects Versions: 2.1.6
>         Environment: Struts 2.1.6
> TC 6.0.14
> JDK 1.6.0.10
>            Reporter: Martin Gainty
>
> If I set encoding the encoding to UTF-8 in struts.properties as 
>  struts.i18n.encoding=UTF-8
> //If I implement the include tag I see all appropriate annotations e.g.
> @StrutsTag(name="include", tldTagClass="org.apache.struts2.views.jsp.IncludeTag", description="Include
a servlet's output " +
>                  "(result of servlet or a JSP page)")
> public class Include extends Component {
>    
> //more importantly the include will support the STRUTS_I18N_ENCODING DefaultEncoding
with this inject //annotation
> @Inject(StrutsConstants.STRUTS_I18N_ENCODING)
>      public void setDefaultEncoding(String encoding) {
>          defaultEncoding = encoding;
>      }
> //but viewing the URL code I see
> @StrutsTag(name="url", tldTagClass="org.apache.struts2.views.jsp.URLTag", description="This
tag is used to create a URL")
> public class URL extends ContextBean
> //there is no setDefaultEncoding which means any new encodings in struts.properties will
not be reflected here
> MCG 22 April 09

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message