diff --git a/spec/tags/1.9/ruby/core/string/unpack/comment_tags.txt b/spec/tags/1.9/ruby/core/string/unpack/comment_tags.txt deleted file mode 100644 index 644ed495d55..00000000000 --- a/spec/tags/1.9/ruby/core/string/unpack/comment_tags.txt +++ /dev/null @@ -1,5 +0,0 @@ -fails(JRUBY-5656):String#unpack ignores directives text from '#' to the first newline -fails(JRUBY-5656):String#unpack ignores directives text from '#' to the end if no newline is present -fails(JRUBY-5656):String#unpack ignores comments at the start of the directives string -fails(JRUBY-5656):String#unpack ignores the entire directive string if it is a comment -fails(JRUBY-5656):String#unpack ignores multiple comments diff --git a/spec/tags/1.9/ruby/core/string/unpack/q_tags.txt b/spec/tags/1.9/ruby/core/string/unpack/q_tags.txt deleted file mode 100644 index 921ae1f3586..00000000000 --- a/spec/tags/1.9/ruby/core/string/unpack/q_tags.txt +++ /dev/null @@ -1 +0,0 @@ -fails(JRUBY-5656):String#unpack with format 'Q' adds nil for each element requested beyond the end of the String diff --git a/spec/tags/1.9/ruby/core/string/unpack/s_tags.txt b/spec/tags/1.9/ruby/core/string/unpack/s_tags.txt deleted file mode 100644 index a5605801f62..00000000000 --- a/spec/tags/1.9/ruby/core/string/unpack/s_tags.txt +++ /dev/null @@ -1,8 +0,0 @@ -fails:String#unpack with format 'S' with modifier '<' and '_' decodes the number of shorts requested by the count modifier -fails:String#unpack with format 'S' with modifier '<' and '_' decodes the remaining shorts when passed the '*' modifier -fails:String#unpack with format 'S' with modifier '<' and '_' does not decode a short when fewer bytes than a short remain and the '*' modifier is passed -fails:String#unpack with format 'S' with modifier '<' and '_' adds nil for each element requested beyond the end of the String -fails:String#unpack with format 'S' with modifier '<' and '!' decodes the number of shorts requested by the count modifier -fails:String#unpack with format 'S' with modifier '<' and '!' decodes the remaining shorts when passed the '*' modifier -fails:String#unpack with format 'S' with modifier '<' and '!' does not decode a short when fewer bytes than a short remain and the '*' modifier is passed -fails:String#unpack with format 'S' with modifier '<' and '!' adds nil for each element requested beyond the end of the String diff --git a/spec/tags/1.9/ruby/core/string/unpack_tags.txt b/spec/tags/1.9/ruby/core/string/unpack_tags.txt deleted file mode 100644 index e02bc30043d..00000000000 --- a/spec/tags/1.9/ruby/core/string/unpack_tags.txt +++ /dev/null @@ -1 +0,0 @@ -fails(JRUBY-5656):String#unpack with 'Q' and 'q' directives pads nil when the string is short diff --git a/src/org/jruby/util/Pack.java b/src/org/jruby/util/Pack.java index 8b6f567e45d..1be362d548c 100644 --- a/src/org/jruby/util/Pack.java +++ b/src/org/jruby/util/Pack.java @@ -950,12 +950,20 @@ public static RubyArray unpack(Ruby runtime, ByteList encodedString, ByteList fo int type = 0; int next = safeGet(format); - while (next != 0) { + mainLoop: while (next != 0) { type = next; next = safeGet(format); if (UNPACK_IGNORE_NULL_CODES.indexOf(type) != -1 && next == 0) { next = safeGetIgnoreNull(format); } + + if (type == '#') { + while (type != '\n') { + if (next == 0) break mainLoop; + type = next; + next = safeGet(format); + } + } // Next indicates to decode using native encoding format if (next == '_' || next == '!') { @@ -978,6 +986,8 @@ public static RubyArray unpack(Ruby runtime, ByteList encodedString, ByteList fo } type = ENDIANESS_CODES.charAt(index); next = safeGet(format); + + if (next == '_' || next == '!') next = safeGet(format); } // How many occurrences of 'type' we want @@ -1574,11 +1584,8 @@ public static void decode(Ruby runtime, ByteBuffer encode, int occurrences, result.append(converter.decode(runtime, encode)); } - // MRI behavior: for 'Q', do not add trailing nils - if (converter != converters['Q']) { - for (; lPadLength-- > 0;) + for (; lPadLength-- > 0;) result.append(runtime.getNil()); - } } public static int encode(Ruby runtime, int occurrences, ByteList result,