ICEfaces
  1. ICEfaces
  2. ICE-1723

Auto-add single quotes to the connectionLostRedirectURI to avoid js errors

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.6DR#5
    • Fix Version/s: 1.7.1
    • Component/s: Framework
    • Labels:
      None
    • Environment:
      any

      Description

      If you specify the connectionLostRedirectURI in your web.xml and forget to single quote the URL, the resulting js configuration string will be corrupted. We should check for this when loading the parameter.

        Activity

        Hide
        Philip Breau added a comment -

        suggested fix:

        Index: C:/Users/Philip/workspace/ICEfaces Head/icefaces/core/src/com/icesoft/faces/context/DOMResponseWriter.java
        ===================================================================
        — C:/Users/Philip/workspace/ICEfaces Head/icefaces/core/src/com/icesoft/faces/context/DOMResponseWriter.java (revision 14269)
        +++ C:/Users/Philip/workspace/ICEfaces Head/icefaces/core/src/com/icesoft/faces/context/DOMResponseWriter.java (working copy)
        @@ -354,10 +354,15 @@
        ElementController.from(session).addInto(body);

        String sessionIDScript = "window.session='" + context.getIceFacesId() + "'; ";
        + String connectionLostRedirectURI = configuration.getAttributeAsSingleQuotedRelativeURL("connectionLostRedirectURI", "null");
        + if( connectionLostRedirectURI == null )

        { + log.warn( configuration.getAttribute("connectionLostRedirectURI","") + " is not a valid URL for 'connectionLostRedirectURI'"); + connectionLostRedirectURI = "null"; + }

        String configurationScript =
        "window.configuration = {" +
        "synchronous: " + configuration.getAttribute("synchronousUpdate", "false") + "," +

        • "redirectURI: " + configuration.getAttribute("connectionLostRedirectURI", "null") + "," +
          + "redirectURI: " + connectionLostRedirectURI + "," +
          "connection: {" +
          "context: '" + context.getApplication().getViewHandler().getResourceURL(context, "/") + "'," +
          "timeout: " + configuration.getAttributeAsLong("connectionTimeout", 30000) + "," +

        Index: C:/Users/Philip/workspace/ICEfaces Head/icefaces/core/src/com/icesoft/faces/webapp/http/common/Configuration.java
        ===================================================================
        — C:/Users/Philip/workspace/ICEfaces Head/icefaces/core/src/com/icesoft/faces/webapp/http/common/Configuration.java (revision 14269)
        +++ C:/Users/Philip/workspace/ICEfaces Head/icefaces/core/src/com/icesoft/faces/webapp/http/common/Configuration.java (working copy)
        @@ -1,5 +1,10 @@
        package com.icesoft.faces.webapp.http.common;

        +import java.util.regex.Pattern;
        +
        +import javax.faces.context.FacesContext;
        +
        +
        public abstract class Configuration

        { public abstract String getName(); @@ -147,4 +152,43 @@ return defaultValue; }

        }
        +
        + public String getAttributeAsSingleQuotedRelativeURL(String name, String defaultValue){
        + String result = defaultValue;
        + try{
        + result = getAttributeAsRelativeURL(name,defaultValue);
        + if( result != null && !result.equals(defaultValue))

        { + + //modify url to ensure it starts with '/ and ends with ' + if( result.startsWith("'")) + result = result.substring(1); + if( result.startsWith("/")) + result = result.substring(1); + result = "'/" + result; + if( !result.endsWith("'")) + result += "'"; + }

        + }
        + catch( ConfigurationException e)

        { + result = null; + }

        +
        + return result;
        + }
        +
        + public String getAttributeAsRelativeURL(String name, String defaultValue)
        + throws ConfigurationException{
        + String result = getAttribute(name);
        + if( result != null ){
        + result = result.trim();
        + if( ! Pattern.matches("^/\\S./+$", result) )

        { + throw new ConfigurationException( result + " is not a valid URL for " + name); + }

        +
        + return result;
        + }
        + return defaultValue;
        + }
        +
        +
        }

        Show
        Philip Breau added a comment - suggested fix: Index: C:/Users/Philip/workspace/ICEfaces Head/icefaces/core/src/com/icesoft/faces/context/DOMResponseWriter.java =================================================================== — C:/Users/Philip/workspace/ICEfaces Head/icefaces/core/src/com/icesoft/faces/context/DOMResponseWriter.java (revision 14269) +++ C:/Users/Philip/workspace/ICEfaces Head/icefaces/core/src/com/icesoft/faces/context/DOMResponseWriter.java (working copy) @@ -354,10 +354,15 @@ ElementController.from(session).addInto(body); String sessionIDScript = "window.session='" + context.getIceFacesId() + "'; "; + String connectionLostRedirectURI = configuration.getAttributeAsSingleQuotedRelativeURL("connectionLostRedirectURI", "null"); + if( connectionLostRedirectURI == null ) { + log.warn( configuration.getAttribute("connectionLostRedirectURI","") + " is not a valid URL for 'connectionLostRedirectURI'"); + connectionLostRedirectURI = "null"; + } String configurationScript = "window.configuration = {" + "synchronous: " + configuration.getAttribute("synchronousUpdate", "false") + "," + "redirectURI: " + configuration.getAttribute("connectionLostRedirectURI", "null") + "," + + "redirectURI: " + connectionLostRedirectURI + "," + "connection: {" + "context: '" + context.getApplication().getViewHandler().getResourceURL(context, "/") + "'," + "timeout: " + configuration.getAttributeAsLong("connectionTimeout", 30000) + "," + Index: C:/Users/Philip/workspace/ICEfaces Head/icefaces/core/src/com/icesoft/faces/webapp/http/common/Configuration.java =================================================================== — C:/Users/Philip/workspace/ICEfaces Head/icefaces/core/src/com/icesoft/faces/webapp/http/common/Configuration.java (revision 14269) +++ C:/Users/Philip/workspace/ICEfaces Head/icefaces/core/src/com/icesoft/faces/webapp/http/common/Configuration.java (working copy) @@ -1,5 +1,10 @@ package com.icesoft.faces.webapp.http.common; +import java.util.regex.Pattern; + +import javax.faces.context.FacesContext; + + public abstract class Configuration { public abstract String getName(); @@ -147,4 +152,43 @@ return defaultValue; } } + + public String getAttributeAsSingleQuotedRelativeURL(String name, String defaultValue){ + String result = defaultValue; + try{ + result = getAttributeAsRelativeURL(name,defaultValue); + if( result != null && !result.equals(defaultValue)) { + + //modify url to ensure it starts with '/ and ends with ' + if( result.startsWith("'")) + result = result.substring(1); + if( result.startsWith("/")) + result = result.substring(1); + result = "'/" + result; + if( !result.endsWith("'")) + result += "'"; + } + } + catch( ConfigurationException e) { + result = null; + } + + return result; + } + + public String getAttributeAsRelativeURL(String name, String defaultValue) + throws ConfigurationException{ + String result = getAttribute(name); + if( result != null ){ + result = result.trim(); + if( ! Pattern.matches("^/ \\S./ +$", result) ) { + throw new ConfigurationException( result + " is not a valid URL for " + name); + } + + return result; + } + return defaultValue; + } + + }
        Hide
        Mircea Toma added a comment -

        Add single quotes. Remove single quotes set by user.

        Show
        Mircea Toma added a comment - Add single quotes. Remove single quotes set by user.

          People

          • Assignee:
            Unassigned
            Reporter:
            Philip Breau
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: