GROOVY-8357: EncodingGroovyMethods.decodeBase64() throws "bad character in base64 value" when meets \t \r (port to 2_4_X)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/a3acf471 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/a3acf471 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/a3acf471 Branch: refs/heads/GROOVY_2_4_X Commit: a3acf47101cf472bc7449aee20e12b6c8ebf7b95 Parents: 30905ec Author: paulk <[email protected]> Authored: Mon Oct 30 12:37:05 2017 +1000 Committer: paulk <[email protected]> Committed: Wed Nov 1 19:17:31 2017 +1000 ---------------------------------------------------------------------- .../runtime/EncodingGroovyMethodsSupport.java | 30 ++++++++++---------- src/test/groovy/Base64Test.groovy | 3 ++ 2 files changed, 18 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/a3acf471/src/main/org/codehaus/groovy/runtime/EncodingGroovyMethodsSupport.java ---------------------------------------------------------------------- diff --git a/src/main/org/codehaus/groovy/runtime/EncodingGroovyMethodsSupport.java b/src/main/org/codehaus/groovy/runtime/EncodingGroovyMethodsSupport.java index a019dad..e4b048d 100644 --- a/src/main/org/codehaus/groovy/runtime/EncodingGroovyMethodsSupport.java +++ b/src/main/org/codehaus/groovy/runtime/EncodingGroovyMethodsSupport.java @@ -24,34 +24,34 @@ package org.codehaus.groovy.runtime; public class EncodingGroovyMethodsSupport { static final byte[] TRANSLATE_TABLE = ( "\u0042\u0042\u0042\u0042\u0042\u0042\u0042\u0042" - // \t \n \r - + "\u0042\u0042\u0041\u0041\u0042\u0042\u0041\u0042" + // \t \n \r + + "\u0042\u0041\u0041\u0042\u0042\u0041\u0042\u0042" // + "\u0042\u0042\u0042\u0042\u0042\u0042\u0042\u0042" // + "\u0042\u0042\u0042\u0042\u0042\u0042\u0042\u0042" - // sp ! " # $ % & ' + // sp ! " # $ % & ' + "\u0041\u0042\u0042\u0042\u0042\u0042\u0042\u0042" - // ( ) * + , - . / + // ( ) * + , - . / + "\u0042\u0042\u0042\u003E\u0042\u0042\u0042\u003F" - // 0 1 2 3 4 5 6 7 + // 0 1 2 3 4 5 6 7 + "\u0034\u0035\u0036\u0037\u0038\u0039\u003A\u003B" - // 8 9 : ; < = > ? + // 8 9 : ; < = > ? + "\u003C\u003D\u0042\u0042\u0042\u0040\u0042\u0042" - // @ A B C D E F G + // @ A B C D E F G + "\u0042\u0000\u0001\u0002\u0003\u0004\u0005\u0006" - // H I J K L M N O + // H I J K L M N O + "\u0007\u0008\t\n\u000B\u000C\r\u000E" - // P Q R S T U V W + // P Q R S T U V W + "\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016" - // X Y Z [ \ ] ^ _ + // X Y Z [ \ ] ^ _ + "\u0017\u0018\u0019\u0042\u0042\u0042\u0042\u0042" - // ' a b c d e f g + // ' a b c d e f g + "\u0042\u001A\u001B\u001C\u001D\u001E\u001F\u0020" - // h i j k l m n o p + // h i j k l m n o + "\u0021\"\u0023\u0024\u0025\u0026\u0027\u0028" - // p q r s t u v w + // p q r s t u v w + "\u0029\u002A\u002B\u002C\u002D\u002E\u002F\u0030" - // x y z + // x y z + "\u0031\u0032\u0033").getBytes(); -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/groovy/blob/a3acf471/src/test/groovy/Base64Test.groovy ---------------------------------------------------------------------- diff --git a/src/test/groovy/Base64Test.groovy b/src/test/groovy/Base64Test.groovy index 42d49b6..713d0c8 100644 --- a/src/test/groovy/Base64Test.groovy +++ b/src/test/groovy/Base64Test.groovy @@ -56,6 +56,9 @@ class Base64Test extends GroovyTestCase { assert line0.size() == 76 assert line0 == 'pzEyMzQ1Njc4OTAtPbEhQKMkJV4mKigpXytxd2VydHl1aW9wW11RV0VSVFlVSU9Qe31hc2RmZ2hq' assert line1 == 'a2w7J1xBU0RGR0hKS0w6InxgenhjdmJubSwuL35aWENWQk5NPD4/A//wDw==' + // check we allow \n \r \t and space to be ignored when decoding for round-tripping purposes + assert encodedBytes.decodeBase64() == testBytes + assert (encodedBytes + '\t ').decodeBase64() == testBytes } void testNonChunked() {
