You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Julius Davies (JIRA)" <ji...@apache.org> on 2009/10/28 07:15:59 UTC

[jira] Created: (CODEC-89) new Base64().encode() appends a CRLF

new Base64().encode() appends a CRLF
------------------------------------

                 Key: CODEC-89
                 URL: https://issues.apache.org/jira/browse/CODEC-89
             Project: Commons Codec
          Issue Type: Bug
    Affects Versions: 1.4
            Reporter: Julius Davies


new Base64().encode() appends a CRLF

{code}
import org.apache.commons.codec.binary.*;

public class B64 {

  public static void main(String[] args) throws Exception {
    Base64 b64 = new Base64();

    String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    String s2 = "aaaaaaaaaa";
    String s3 = "a";
    
    byte[] b1 = s1.getBytes("UTF-8");
    byte[] b2 = s2.getBytes("UTF-8");
    byte[] b3 = s3.getBytes("UTF-8");

    byte[] result;
    result = Base64.encodeBase64(b1);
    System.out.println("[" + new String(result, "UTF-8") + "]");
    result = b64.encode(b1);
    System.out.println("[" + new String(result, "UTF-8") + "]");

    result = Base64.encodeBase64(b2);
    System.out.println("[" + new String(result, "UTF-8") + "]");
    result = b64.encode(b2);
    System.out.println("[" + new String(result, "UTF-8") + "]");

    result = Base64.encodeBase64(b3);
    System.out.println("[" + new String(result, "UTF-8") + "]");
    result = b64.encode(b3);
    System.out.println("[" + new String(result, "UTF-8") + "]");

  }
}
{code}


Here's my output:

{noformat}
$ java -cp commons-codec-1.3.jar:. B64
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYQ==]
[YQ==]
[YQ==]


$ java -cp commons-codec-1.4.jar:. B64
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
]
[YWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYQ==
]
[YQ==]
[YQ==
]
{noformat}


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


[jira] Commented: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Nikolas Falco (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12804463#action_12804463 ] 

Nikolas Falco commented on CODEC-89:
------------------------------------

I quote Daniel Fernández, we have the same problem.
We should patch all framework code to work.

> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: Base64.patch, codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Commented: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12785109#action_12785109 ] 

Sebb commented on CODEC-89:
---------------------------

Patch (dated 2009-10-28 04:52 PM) looks OK, except I think it looks odd to do:

this(NO_CHUNKING, CHUNK_SEPARATOR, urlSafe);

Why provide a CHUNK_SEPARATOR if there's no chunking?

Seems to me it would be better to use null, and make corresponding changes to the ctor 
Base64(int lineLength, byte[] lineSeparator, boolean urlSafe)
so that lineSeparator == null IFF lineLength==0
This would have the benefit that accidental use of the lineSeparator would trigger an NPE.

The current code outside the ctor only accesses lineSeparator if lineLength > 0, which is as it should be.

> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Commented: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12781274#action_12781274 ] 

Gary Gregory commented on CODEC-89:
-----------------------------------

What a pickle. The current behavior is documented in Javadocs but the API behavior for 1.4 is released and different from 1.3. What should in 1.5? Go back to 1.3 behavior? That seems like asking call sites a lot, switching twice. What does the community thinks?

> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Commented: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12801870#action_12801870 ] 

Henri Yandell commented on CODEC-89:
------------------------------------

+1 to a 1.4.1 release that goes back to the 1.3 approach (or rather, that does the right thing. I'm inferring that it's agreed that 1.3 did it 'right'). 

> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: Base64.patch, codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Commented: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Mat Booth (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12784460#action_12784460 ] 

Mat Booth commented on CODEC-89:
--------------------------------

I'd prefer to see a 1.4.1 release with the old behaviour. It seems against the spirit of minor version bump (like 1.3 to 1.4) to change the behaviour of the interface.

It definitely feels like a regression to me -- I'm tempted to apply this patch to the commons-codec distributed by Fedora Linux (I am the maintainer there).

> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Commented: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12784589#action_12784589 ] 

Sebb commented on CODEC-89:
---------------------------

Note that the behaviour of 

new Base64(0).encode() 
is the same as 
Base64.encodeBase64()

> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Issue Comment Edited: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Keegan Witt (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12842656#action_12842656 ] 

Keegan Witt edited comment on CODEC-89 at 3/8/10 1:53 PM:
----------------------------------------------------------

This is also present for non-empty constructors, which the patch doesn't seem to address.  I think this is what CODEC-94 was trying to say.  If you construct a Base64, specifying lineSeparator and/or lineLength, this is ignored with you do the encoding.  For example,

System.out.println("\ \n: " + "\n".getBytes());     // (note the space was needed because Jira was eating my \)
System.out.println("\\r\ \n: " + "\r\n".getBytes());
String unencodedString = "aaaaaaaaaaaaaaaa";
Base64 encoder = new Base64(4, "\n".getBytes());
String encodedString = new String( encoder.encodeBase64( unencodedString .getBytes(), true ) );
System.out.println(encodedString);
System.out.println(encodedString.getBytes());

You'll note the byte sequence ends with [13, 10] instead of [10], and the line didn't get split at 4 as specified in the constructor, but by 76.  You can double check this using a larger string to encode.

I believe at least some of the blame lies with line 817 of Base64.java:
Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe);
If I request the encoding to be chunked, it will call the constructor public Base64(boolean urlSafe), which does
this(CHUNK_SIZE, CHUNK_SEPARATOR, urlSafe); (line 244).  As you can see, this overrides any parameters passed into the constructor.

Or am I misunderstanding how this is supposed to work?

      was (Author: keegan):
    This is also present for non-empty constructors, which the patch doesn't seem to address.  I think this is what CODEC-94 was trying to say.  If you construct a Base64, specifying lineSeparator and/or lineLength, this is ignored with you do the encoding.  For example,

System.out.println("\\n: " + "\n".getBytes());
System.out.println("\\r\\n: " + "\r\n".getBytes());
String unencodedString = "aaaaaaaaaaaaaaaa";
Base64 encoder = new Base64(4, "\n".getBytes());
String encodedString = new String( encoder.encodeBase64( unencodedString .getBytes(), true ) );
System.out.println(encodedString);
System.out.println(encodedString.getBytes());

You'll note the byte sequence ends with [13, 10] instead of [10], and the line didn't get split at 4 as specified in the constructor, but by 76.  You can double check this using a larger string to encode.

I believe at least some of the blame lies with line 817 of Base64.java:
Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe);
If I request the encoding to be chunked, it will call the constructor public Base64(boolean urlSafe), which does
this(CHUNK_SIZE, CHUNK_SEPARATOR, urlSafe); (line 244).  As you can see, this overrides any parameters passed into the constructor.

Or am I misunderstanding how this is supposed to work?
  
> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: Base64.patch, codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Commented: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12785116#action_12785116 ] 

Sebb commented on CODEC-89:
---------------------------

Having second thoughts - although the patch looks OK, it actually changes the behaviour of *two* constructors:

public Base64()
public Base64(boolean urlSafe)

Since the second ctor is @since 1.4, there is no need to - and therefore we should not - change its behaviour.

The simplest fix is to change the null ctor to call this(0), and change any code that calls the null ctor to call Base64(false) instead.

Patch to follow.

> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Updated: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Sebb (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb updated CODEC-89:
----------------------

    Attachment: Base64.patch

Minimal patch to revert null ctor to 1.3 behaviour.

Note that the tests all still work, so clearly the tests are inadequate.

In fact the tests still work even if the IO Stream files are not patched.

> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: Base64.patch, codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Commented: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Keegan Witt (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12842656#action_12842656 ] 

Keegan Witt commented on CODEC-89:
----------------------------------

This is also present for non-empty constructors, which the patch doesn't seem to address.  I think this is what CODEC-94 was trying to say.  If you construct a Base64, specifying lineSeparator and/or lineLength, this is ignored with you do the encoding.  For example,

System.out.println("\\n: " + "\n".getBytes());
System.out.println("\\r\\n: " + "\r\n".getBytes());
String unencodedString = "aaaaaaaaaaaaaaaa";
Base64 encoder = new Base64(4, "\n".getBytes());
String encodedString = new String( encoder.encodeBase64( unencodedString .getBytes(), true ) );
System.out.println(encodedString);
System.out.println(encodedString.getBytes());

You'll note the byte sequence ends with [13, 10] instead of [10], and the line didn't get split at 4 as specified in the constructor, but by 76.  You can double check this using a larger string to encode.

I believe at least some of the blame lies with line 817 of Base64.java:
Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe);
If I request the encoding to be chunked, it will call the constructor public Base64(boolean urlSafe), which does
this(CHUNK_SIZE, CHUNK_SEPARATOR, urlSafe); (line 244).  As you can see, this overrides any parameters passed into the constructor.

Or am I misunderstanding how this is supposed to work?

> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: Base64.patch, codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Commented: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12781305#action_12781305 ] 

Gary Gregory commented on CODEC-89:
-----------------------------------

I see a change for a 1.4.1 or a 1.5 as the same issue since the API behavior would change again:

1.3: Behavior A
1.4: Behavior B
1.4.1 and 1.5: Behavior A again?

In either case that is asking clients to change their code twice, back and forth. That seems painful. 

If you want, you can post to the dev list to ask for the community's feedback. It would be good to see what other people think.

> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Commented: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Julius Davies (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12781295#action_12781295 ] 

Julius Davies commented on CODEC-89:
------------------------------------

Could we put out a fix as "1.4.1" ?

> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Issue Comment Edited: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Keegan Witt (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12842656#action_12842656 ] 

Keegan Witt edited comment on CODEC-89 at 3/8/10 1:53 PM:
----------------------------------------------------------

This is also present for non-empty constructors, which the patch doesn't seem to address.  I think this is what CODEC-94 was trying to say.  If you construct a Base64, specifying lineSeparator and/or lineLength, this is ignored with you do the encoding.  For example,

System.out.println("\ \n: " + "\n".getBytes());     // (note the space was needed because Jira was eating my \\ )
System.out.println("\\r\ \n: " + "\r\n".getBytes());
String unencodedString = "aaaaaaaaaaaaaaaa";
Base64 encoder = new Base64(4, "\n".getBytes());
String encodedString = new String( encoder.encodeBase64( unencodedString .getBytes(), true ) );
System.out.println(encodedString);
System.out.println(encodedString.getBytes());

You'll note the byte sequence ends with [13, 10] instead of [10], and the line didn't get split at 4 as specified in the constructor, but by 76.  You can double check this using a larger string to encode.

I believe at least some of the blame lies with line 817 of Base64.java:
Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe);
If I request the encoding to be chunked, it will call the constructor public Base64(boolean urlSafe), which does
this(CHUNK_SIZE, CHUNK_SEPARATOR, urlSafe); (line 244).  As you can see, this overrides any parameters passed into the constructor.

Or am I misunderstanding how this is supposed to work?

      was (Author: keegan):
    This is also present for non-empty constructors, which the patch doesn't seem to address.  I think this is what CODEC-94 was trying to say.  If you construct a Base64, specifying lineSeparator and/or lineLength, this is ignored with you do the encoding.  For example,

System.out.println("\ \n: " + "\n".getBytes());     // (note the space was needed because Jira was eating my \)
System.out.println("\\r\ \n: " + "\r\n".getBytes());
String unencodedString = "aaaaaaaaaaaaaaaa";
Base64 encoder = new Base64(4, "\n".getBytes());
String encodedString = new String( encoder.encodeBase64( unencodedString .getBytes(), true ) );
System.out.println(encodedString);
System.out.println(encodedString.getBytes());

You'll note the byte sequence ends with [13, 10] instead of [10], and the line didn't get split at 4 as specified in the constructor, but by 76.  You can double check this using a larger string to encode.

I believe at least some of the blame lies with line 817 of Base64.java:
Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe);
If I request the encoding to be chunked, it will call the constructor public Base64(boolean urlSafe), which does
this(CHUNK_SIZE, CHUNK_SEPARATOR, urlSafe); (line 244).  As you can see, this overrides any parameters passed into the constructor.

Or am I misunderstanding how this is supposed to work?
  
> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: Base64.patch, codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Commented: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Mat Booth (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12784741#action_12784741 ] 

Mat Booth commented on CODEC-89:
--------------------------------

> Note that the behaviour of
> 
> new Base64(0).encode()
> is the same as
> Base64.encodeBase64()

So it is... Is that documented anywhere?

A note in the compatibility section of the release notes that "new Base64()" should be changed to "new Base64(0)" would be awesome.

> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Commented: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Matthias (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12801707#action_12801707 ] 

Matthias commented on CODEC-89:
-------------------------------

I can only second that.

I'm the developer of the Signpost OAuth project, and people are complaining that Signpost breaks with CC-1.4, while it worked fine with 1.3.

I already changed my code to trim() any output of the Base64 methods, but apparently, that's not enough. Users are still reporting issues that disappear when switching to 1.3.

> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: Base64.patch, codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Issue Comment Edited: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Keegan Witt (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12842656#action_12842656 ] 

Keegan Witt edited comment on CODEC-89 at 3/8/10 1:55 PM:
----------------------------------------------------------

This is also present for non-empty constructors, which the patch doesn't seem to address.  I think this is what CODEC-94 was trying to say.  If you construct a Base64, specifying lineSeparator and/or lineLength, this is ignored with you do the encoding.  For example,

System.out.println("&#92;&#92;n: " + "&#92;n".getBytes());
System.out.println("&#92;&#92;r&#92;&#92;n: " + "&#92;r&#92;n".getBytes());
String unencodedString = "aaaaaaaaaaaaaaaa";
Base64 encoder = new Base64(4, "\n".getBytes());
String encodedString = new String( encoder.encodeBase64( unencodedString .getBytes(), true ) );
System.out.println(encodedString);
System.out.println(encodedString.getBytes());

You'll note the byte sequence ends with [13, 10] instead of [10], and the line didn't get split at 4 as specified in the constructor, but by 76.  You can double check this using a larger string to encode.

I believe at least some of the blame lies with line 817 of Base64.java:
Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe);
If I request the encoding to be chunked, it will call the constructor public Base64(boolean urlSafe), which does
this(CHUNK_SIZE, CHUNK_SEPARATOR, urlSafe); (line 244).  As you can see, this overrides any parameters passed into the constructor.

Or am I misunderstanding how this is supposed to work?

      was (Author: keegan):
    This is also present for non-empty constructors, which the patch doesn't seem to address.  I think this is what CODEC-94 was trying to say.  If you construct a Base64, specifying lineSeparator and/or lineLength, this is ignored with you do the encoding.  For example,

System.out.println("\ \n: " + "\n".getBytes());     // (note the space was needed because Jira was eating my \\ )
System.out.println("\\r\ \n: " + "\r\n".getBytes());
String unencodedString = "aaaaaaaaaaaaaaaa";
Base64 encoder = new Base64(4, "\n".getBytes());
String encodedString = new String( encoder.encodeBase64( unencodedString .getBytes(), true ) );
System.out.println(encodedString);
System.out.println(encodedString.getBytes());

You'll note the byte sequence ends with [13, 10] instead of [10], and the line didn't get split at 4 as specified in the constructor, but by 76.  You can double check this using a larger string to encode.

I believe at least some of the blame lies with line 817 of Base64.java:
Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe);
If I request the encoding to be chunked, it will call the constructor public Base64(boolean urlSafe), which does
this(CHUNK_SIZE, CHUNK_SEPARATOR, urlSafe); (line 244).  As you can see, this overrides any parameters passed into the constructor.

Or am I misunderstanding how this is supposed to work?
  
> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: Base64.patch, codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Updated: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Julius Davies (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Julius Davies updated CODEC-89:
-------------------------------

    Attachment: codec-89.patch

codec-89.patch attached which fixes this.  Also introduces some JUnit tests to avoid this problem in the future.

Note:  I changed the behavior of the Base64.encodeBase64String() method introduced in commons-codec-1.4 so that it also no longer chunks its output.  Two lines of the JUnit tests adjusted to reflect this change.

> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Updated: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Julius Davies (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Julius Davies updated CODEC-89:
-------------------------------

    Description: 
The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.


{code}
import org.apache.commons.codec.binary.*;

public class B64 {

  public static void main(String[] args) throws Exception {
    Base64 b64 = new Base64();

    String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    String s2 = "aaaaaaaaaa";
    String s3 = "a";
    
    byte[] b1 = s1.getBytes("UTF-8");
    byte[] b2 = s2.getBytes("UTF-8");
    byte[] b3 = s3.getBytes("UTF-8");

    byte[] result;
    result = Base64.encodeBase64(b1);
    System.out.println("[" + new String(result, "UTF-8") + "]");
    result = b64.encode(b1);
    System.out.println("[" + new String(result, "UTF-8") + "]");

    result = Base64.encodeBase64(b2);
    System.out.println("[" + new String(result, "UTF-8") + "]");
    result = b64.encode(b2);
    System.out.println("[" + new String(result, "UTF-8") + "]");

    result = Base64.encodeBase64(b3);
    System.out.println("[" + new String(result, "UTF-8") + "]");
    result = b64.encode(b3);
    System.out.println("[" + new String(result, "UTF-8") + "]");

  }
}
{code}


Here's my output:

{noformat}
$ java -cp commons-codec-1.3.jar:. B64
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYQ==]
[YQ==]
[YQ==]


$ java -cp commons-codec-1.4.jar:. B64
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
]
[YWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYQ==
]
[YQ==]
[YQ==
]
{noformat}


  was:
new Base64().encode() appends a CRLF

{code}
import org.apache.commons.codec.binary.*;

public class B64 {

  public static void main(String[] args) throws Exception {
    Base64 b64 = new Base64();

    String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    String s2 = "aaaaaaaaaa";
    String s3 = "a";
    
    byte[] b1 = s1.getBytes("UTF-8");
    byte[] b2 = s2.getBytes("UTF-8");
    byte[] b3 = s3.getBytes("UTF-8");

    byte[] result;
    result = Base64.encodeBase64(b1);
    System.out.println("[" + new String(result, "UTF-8") + "]");
    result = b64.encode(b1);
    System.out.println("[" + new String(result, "UTF-8") + "]");

    result = Base64.encodeBase64(b2);
    System.out.println("[" + new String(result, "UTF-8") + "]");
    result = b64.encode(b2);
    System.out.println("[" + new String(result, "UTF-8") + "]");

    result = Base64.encodeBase64(b3);
    System.out.println("[" + new String(result, "UTF-8") + "]");
    result = b64.encode(b3);
    System.out.println("[" + new String(result, "UTF-8") + "]");

  }
}
{code}


Here's my output:

{noformat}
$ java -cp commons-codec-1.3.jar:. B64
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYQ==]
[YQ==]
[YQ==]


$ java -cp commons-codec-1.4.jar:. B64
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
]
[YWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYQ==
]
[YQ==]
[YQ==
]
{noformat}


        Summary: new Base64().encode() appends a CRLF, and chunks results into 76 character lines  (was: new Base64().encode() appends a CRLF)

> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Commented: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Daniel Fernández (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12801703#action_12801703 ] 

Daniel Fernández commented on CODEC-89:
---------------------------------------

I am the lead developer of Jasypt [http://www.jasypt.org], which uses this wonderful Commons-Codec library as a dependency. Base64 is the default encoding for encrypted output in Jasypt.

This issue is of an inmense importance to Jasypt. If my vote makes any difference, please, go back to the 1.3 behaviour ASAP, as this is breaking compatibiliy of encrypted texts for many of our users and not allowing them to use an up-to-date version of commons-codec. I would be forced to remove commons-codec from jasypt's dependency list if this bug is not solved soon :-(

Thanks.
Daniel.


> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: Base64.patch, codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Resolved: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Sebb (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb resolved CODEC-89.
-----------------------

    Resolution: Fixed

> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: Base64.patch, codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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


[jira] Commented: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

Posted by "Keegan Witt (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12842711#action_12842711 ] 

Keegan Witt commented on CODEC-89:
----------------------------------

My apologies, I was calling a static method from an instanced class.  I see now I should have been doing
String encodedString = new String( encoder.encode( unencodedString .getBytes() ) );

> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>         Attachments: Base64.patch, codec-89.patch
>
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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