Skip to content

Commit

Permalink
Use ByteList length to end traversal while parsing out popen args.
Browse files Browse the repository at this point in the history
Fixes #2047.
  • Loading branch information
headius committed Oct 16, 2014
1 parent ef1eb50 commit 4b2c130
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
9 changes: 5 additions & 4 deletions core/src/main/java/org/jruby/util/io/PopenExecutor.java
Expand Up @@ -1847,12 +1847,13 @@ public int compare(String o1, String o2) {
List<byte[]> argv_buf = new ArrayList<>();
pBytes = prog.getByteList().unsafeBytes();
p = prog.getByteList().begin();
while (p < pBytes.length){
while (p < pBytes.length && (pBytes[p] == ' ' || pBytes[p] == '\t'))
int pEnd = prog.getByteList().length() + p;
while (p < pEnd){
while (p < pEnd && (pBytes[p] == ' ' || pBytes[p] == '\t'))
p++;
if (p < pBytes.length){
if (p < pEnd){
int w = p;
while (p < pBytes.length && pBytes[p] != ' ' && pBytes[p] != '\t')
while (p < pEnd && pBytes[p] != ' ' && pBytes[p] != '\t')
p++;
argv_buf.add(Arrays.copyOfRange(pBytes, w, p));
eargp.argv_buf = argv_buf;
Expand Down
23 changes: 11 additions & 12 deletions test/jruby/test_backquote.rb
Expand Up @@ -25,19 +25,18 @@ def test_system_special_commands
end
end

# GH #2047 backquote fails with null byte ArgumentError
#JRUBY-2251
# def test_empty_backquotes
# if (!WINDOWS)
# assert_raise(Errno::ENOENT) {``}
# assert_raise(Errno::ENOENT) {` `}
# assert_raise(Errno::ENOENT) {`\n`}
# else # we just check that empty backquotes won't blow up JRuby
# `` rescue nil
# ` ` rescue nil
# `\n` rescue nil
# end
# end
def test_empty_backquotes
if (!WINDOWS)
assert_raise(Errno::ENOENT) {``}
assert_raise(Errno::ENOENT) {` `}
assert_raise(Errno::ENOENT) {`\n`}
else # we just check that empty backquotes won't blow up JRuby
`` rescue nil
` ` rescue nil
`\n` rescue nil
end
end

# http://jira.codehaus.org/browse/JRUBY-1557
def test_backquotes_with_redirects_pass_through_shell
Expand Down

0 comments on commit 4b2c130

Please sign in to comment.