You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by Norman Maurer <no...@apache.org> on 2009/05/31 14:26:33 UTC

Re: svn commit: r780418 - in /james/jspf/trunk/resolver/src: main/java/org/apache/james/jspf/core/MacroExpand.java test/java/org/apache/james/jspf/core/MacroExpandTest.java

Hi,

I not added the backslash because backslashes are not allowed in
emailaddresses, anyway It can't harm ;-)

Thx,
Norman

2009/5/31  <ba...@apache.org>:
> Author: bago
> Date: Sun May 31 12:22:44 2009
> New Revision: 780418
>
> URL: http://svn.apache.org/viewvc?rev=780418&view=rev
> Log:
> Also add escaping for backslash in regex replace strings (JSPF-71)
> From javadocs, both dollar and backslash need escaping.
> (also replaced tabs with spaces for our formatting convention).
>
> Modified:
>    james/jspf/trunk/resolver/src/main/java/org/apache/james/jspf/core/MacroExpand.java
>    james/jspf/trunk/resolver/src/test/java/org/apache/james/jspf/core/MacroExpandTest.java
>
> Modified: james/jspf/trunk/resolver/src/main/java/org/apache/james/jspf/core/MacroExpand.java
> URL: http://svn.apache.org/viewvc/james/jspf/trunk/resolver/src/main/java/org/apache/james/jspf/core/MacroExpand.java?rev=780418&r1=780417&r2=780418&view=diff
> ==============================================================================
> --- james/jspf/trunk/resolver/src/main/java/org/apache/james/jspf/core/MacroExpand.java (original)
> +++ james/jspf/trunk/resolver/src/main/java/org/apache/james/jspf/core/MacroExpand.java Sun May 31 12:22:44 2009
> @@ -573,16 +573,16 @@
>      * @return escaped string
>      */
>     private String escapeForMatcher(String raw) {
> -       StringBuffer sb= new StringBuffer();
> -
> -       for (int i = 0; i < raw.length(); i++) {
> -               char c = raw.charAt(i);
> -               if (c == '$') {
> -                       sb.append('\\');
> -               }
> -               sb.append(c);
> -       }
> -       return sb.toString();
> +        StringBuffer sb = new StringBuffer();
> +
> +        for (int i = 0; i < raw.length(); i++) {
> +            char c = raw.charAt(i);
> +            if (c == '$' || c == '\\') {
> +                sb.append('\\');
> +            }
> +            sb.append(c);
> +        }
> +        return sb.toString();
>     }
>
>  }
> \ No newline at end of file
>
> Modified: james/jspf/trunk/resolver/src/test/java/org/apache/james/jspf/core/MacroExpandTest.java
> URL: http://svn.apache.org/viewvc/james/jspf/trunk/resolver/src/test/java/org/apache/james/jspf/core/MacroExpandTest.java?rev=780418&r1=780417&r2=780418&view=diff
> ==============================================================================
> --- james/jspf/trunk/resolver/src/test/java/org/apache/james/jspf/core/MacroExpandTest.java (original)
> +++ james/jspf/trunk/resolver/src/test/java/org/apache/james/jspf/core/MacroExpandTest.java Sun May 31 12:22:44 2009
> @@ -188,16 +188,33 @@
>     }
>
>     public void testLocalPartWithSpecialChars() throws PermErrorException {
> -
> -
> -       assertEquals("+exists:CL.192.0.2.3.FR.test{$LNAME}@email.example.com.spf.test.com",defIp4me.expand("+exists:CL.%{i}.FR.%{s}.spf.test.com", new rfcIP4MacroData() {
> -               public String getMailFrom() {
> -                       return "test{$LNAME}@email.example.com";
> -               }
> -                  public String getCurrentSenderPart() {
> -                   return "test{$LNAME}";
> -               }
> -       }, MacroExpand.DOMAIN));
> +
> +        assertEquals(
> +                "+exists:CL.192.0.2.3.FR.test{$LNAME}@email.example.com.spf.test.com",
> +                defIp4me.expand("+exists:CL.%{i}.FR.%{s}.spf.test.com",
> +                        new rfcIP4MacroData() {
> +                            public String getMailFrom() {
> +                                return "test{$LNAME}@email.example.com";
> +                            }
> +
> +                            public String getCurrentSenderPart() {
> +                                return "test{$LNAME}";
> +                            }
> +                        }, MacroExpand.DOMAIN));
> +
> +        // not sure if \ is allowed in email, but anyway make sure we correctly handle also backslash.
> +        assertEquals(
> +                "+exists:CL.192.0.2.3.FR.tes\\t{$LNAME}@email.example.com.spf.test.com",
> +                defIp4me.expand("+exists:CL.%{i}.FR.%{s}.spf.test.com",
> +                        new rfcIP4MacroData() {
> +                            public String getMailFrom() {
> +                                return "tes\\t{$LNAME}@email.example.com";
> +                            }
> +
> +                            public String getCurrentSenderPart() {
> +                                return "tes\\t{$LNAME}";
> +                            }
> +                        }, MacroExpand.DOMAIN));
>     }
>
>  }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org