Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9e28f8800c9f
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1fc06043c32c
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Jan 12, 2017

  1. Copy the full SHA
    c923350 View commit details
  2. Merge pull request #4438 from k77ch7/fix_base64_decode64

    fix Base64#decode64 behavior
    enebo authored Jan 12, 2017
    Copy the full SHA
    1fc0604 View commit details
Showing with 19 additions and 2 deletions.
  1. +3 −2 core/src/main/java/org/jruby/util/Pack.java
  2. +16 −0 spec/jruby/base64_decode_spec.rb
5 changes: 3 additions & 2 deletions core/src/main/java/org/jruby/util/Pack.java
Original file line number Diff line number Diff line change
@@ -1196,12 +1196,13 @@ else if (encode.hasRemaining()) {
lElem[index++] = (byte)((a << 2 | b >> 4) & 255);
lElem[index++] = (byte)((b << 4 | c >> 2) & 255);
lElem[index++] = (byte)((c << 6 | d) & 255);
a = -1;
}

if (a != -1 && b != -1) {
if (c == -1 && s == '=') {
if (c == -1) {
lElem[index++] = (byte)((a << 2 | b >> 4) & 255);
} else if(c != -1 && s == '=') {
} else {
lElem[index++] = (byte)((a << 2 | b >> 4) & 255);
lElem[index++] = (byte)((b << 4 | c >> 2) & 255);
}
16 changes: 16 additions & 0 deletions spec/jruby/base64_decode_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require "rspec"
require "base64"

describe "Base64#decode64" do
it "return the correct result when missing paddings" do
expect(Base64.decode64("YQ")).to eq "a"
expect(Base64.decode64("YWI")).to eq "ab"
expect(Base64.decode64("YWJj")).to eq "abc"
end
end

describe "Base64#strict_decode64" do
it "raise ArgumentError when missing paddings" do
expect{ Base64.strict_decode64("YQ") }.to raise_error(ArgumentError)
end
end