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: 79ff742663e4
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 23d2e1225014
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Mar 7, 2017

  1. Copy the full SHA
    4ba5e5e View commit details
  2. Add spec which shows ArgumentError if missing repeated key.

    This fixed JRuby #4523.
    enebo committed Mar 7, 2017
    Copy the full SHA
    23d2e12 View commit details
Showing with 8 additions and 6 deletions.
  1. +4 −6 core/src/main/java/org/jruby/util/Sprintf.java
  2. +4 −0 spec/ruby/core/kernel/sprintf_spec.rb
10 changes: 4 additions & 6 deletions core/src/main/java/org/jruby/util/Sprintf.java
Original file line number Diff line number Diff line change
@@ -358,7 +358,6 @@ private static boolean rubySprintfToBuffer(ByteList buf, CharSequence charFormat
int length;
int start;
int mark;
ByteList name = null;
Encoding encoding = null;

// used for RubyString functions to manage encoding, etc
@@ -379,6 +378,7 @@ private static boolean rubySprintfToBuffer(ByteList buf, CharSequence charFormat
}

while (offset < length) {
ByteList name = null;
start = offset;
for ( ; offset < length && format[offset] != '%'; offset++) {}

@@ -428,11 +428,9 @@ private static boolean rubySprintfToBuffer(ByteList buf, CharSequence charFormat
}

if (nameEnd == nameStart) raiseArgumentError(args, ERR_MALFORMED_NAME);

ByteList oldName = name;
name = new ByteList(format, nameStart, nameEnd - nameStart, encoding, false);

if (oldName != null) raiseArgumentError(args, "name<" + name + "> after <" + oldName + ">");
ByteList newName = new ByteList(format, nameStart, nameEnd - nameStart, encoding, false);
if (name != null) raiseArgumentError(args, "named<" + newName + "> after <" + name + ">");
name = newName;
// we retrieve value from hash so we can generate argument error as side-effect.
args.nextObject = args.getHashValue(name);

4 changes: 4 additions & 0 deletions spec/ruby/core/kernel/sprintf_spec.rb
Original file line number Diff line number Diff line change
@@ -78,6 +78,10 @@
it "raises KeyError when no matching key is in second argument" do
lambda { sprintf("%<foo>f", {}) }.should raise_error(KeyError)
end

it "raises ArgumentError if missing second named argument" do
lambda { sprintf("%<key><foo>d", {key: 1}) }.should raise_error(ArgumentError)
end
end

describe "with negative values" do