FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Additional fixes for scheme-based globbing (9.4) by headius · Pull Request #8980 · jruby/jruby · GitHub

/ jruby Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (2) .rb  (2) .txt  (4) .yml  (1) All 4 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
29 changes: 28 additions & 1 deletion .github/workflows/ci.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,34 @@ jobs:

strategy:
matrix:
target: ['test:mri:core:jit', 'test:mri:extra', 'spec:ruby:fast:jit', 'test:mri:stdlib', 'spec:ruby:slow', 'spec:ruby:debug', 'test:jruby:aot', 'test:slow_suites', 'spec:compiler', 'spec:regression', 'spec:jruby', 'spec:jrubyc', 'spec:profiler']
target: ['test:mri:core:jit', 'test:mri:extra', 'spec:ruby:fast:jit', 'test:mri:stdlib', 'spec:ruby:slow', 'spec:ruby:debug', 'test:jruby:aot', 'test:slow_suites', 'spec:compiler', 'spec:regression', 'spec:jrubyc', 'spec:profiler']
fail-fast: false

name: rake ${{ matrix.target }} (Java 8)

steps:
- name: checkout
uses: actions/checkout@v3
- name: set up java 8
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '8'
cache: 'maven'
- name: bootstrap
run: mvn -ntp -Pbootstrap clean package
- name: bundle install
run: bin/jruby --dev -S bundle install
- name: rake ${{ matrix.target }}
run: bin/jruby -S rake ${{ matrix.target }}

rake-test-8-multiplatform:
runs-on: ${{ matrix.platform }}

strategy:
matrix:
target: ['spec:jruby']
platform: ['ubuntu-latest', 'macos-latest']
fail-fast: false

name: rake ${{ matrix.target }} (Java 8)
Expand Down
19 changes: 15 additions & 4 deletions core/src/main/java/org/jruby/util/Dir.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static org.jruby.util.ByteList.memcmp;
import static org.jruby.util.StringSupport.EMPTY_STRING_ARRAY;
import static org.jruby.util.StringSupport.codePoint;
import static org.jruby.util.StringSupport.memchr;

/**
* This class exists as a counterpart to the dir.c file in
Expand Down Expand Up @@ -760,6 +761,9 @@ private static int findScheme(byte[] path, int begin, int end) {
if (schemeStr.startsWith("uri:")) return 4;
if (schemeStr.startsWith("file:")) return 5;
if (schemeStr.startsWith("classpath:")) return 10;
if (schemeStr.startsWith("jar:file:")) {
return memchr(path, begin, '!', end - begin) + 1;
}
return -1;
}

Expand Down Expand Up @@ -819,11 +823,15 @@ private static int addToResultIfExists(Ruby runtime, String cwd, byte[] bytes, i

private static int glob_helper(Ruby runtime, String cwd, ByteList path, int sub, int flags, GlobFunc<GlobArgs> func, GlobArgs arg) {
int begin = path.getBegin();
final int end = begin + path.length();
int end = begin + path.length();
final Encoding enc = path.getEncoding();
final byte[] bytes = path.getUnsafeBytes();
byte[] bytes = path.getUnsafeBytes();
final byte[] scheme = extractScheme(bytes, begin, end);
if (scheme != null) begin += scheme.length;
if (scheme != null) {
bytes = Arrays.copyOfRange(bytes, begin + scheme.length, end);
begin = 0;
end = bytes.length;
}
return glob_helper(runtime, cwd, scheme, bytes, begin, end, enc, sub, flags, func, arg);
}

Expand Down Expand Up @@ -1004,7 +1012,10 @@ private static int glob_helper(Ruby runtime, String cwd, byte[] scheme,
for ( DirGlobber globber : links ) {
final ByteList link = globber.link;
if ( status == 0 ) {
resource = JRubyFile.createResource(runtime, cwd, new String(link.unsafeBytes(), link.begin(), link.length(), enc.getCharset()));
String fullPath = scheme != null ?
new String(prependScheme(scheme, link.unsafeBytes(), link.begin(), link.length()), enc.getCharset()) :
new String(link.unsafeBytes(), link.begin(), link.length(), enc.getCharset());
resource = JRubyFile.createResource(runtime, cwd, fullPath);
if ( resource.isDirectory() ) {
final int len = link.getRealSize();
buf.length(0);
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/jruby/util/JarResource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ else if (pathname.startsWith("file:")) {
// normalize path -- issue #2017
if (StringSupport.startsWith(entryPath, '/', '/')) entryPath = entryPath.substring(1);

// special case: "jar:file:blah.jar!." is just "jar:file:blah.jar!"
if (entryPath.equals(".")) entryPath = "";

// TODO: Do we really need to support both test.jar!foo/bar.rb and test.jar!/foo/bar.rb cases?
JarResource resource = createJarResource(jarPath, entryPath, false);

Expand Down
1 change: 1 addition & 0 deletions spec/jruby/core/dir/fixtures/test1.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test1
1 change: 1 addition & 0 deletions spec/jruby/core/dir/fixtures/test2.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test2
1 change: 1 addition & 0 deletions spec/jruby/core/dir/fixtures/test3.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test3
1 change: 1 addition & 0 deletions spec/jruby/core/dir/fixtures/testdir/test4.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test4
101 changes: 99 additions & 2 deletions spec/jruby/core/dir/glob_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'rspec'
require 'fileutils'
require 'tmpdir'

describe "Dir.glob" do
let(:dir_name) { 'test_dir!' }
Expand All @@ -17,15 +18,111 @@
it 'can glob directories with URI special chars in it (GH-2264)' do
expect(Dir.glob("#{dir_name}/**/*").size).to eq 1
end
end

describe "Dir.glob" do
# We have common option processing code and a logic mistake made
# us process argv[2] as both a kwarg then try to convert it to an
# integer.
it "does not think the third arg should be an integer when it is kwargs" do
expect { Dir["*", "*", base: "."] }.not_to raise_error
end

describe "with a uri:classloader: scheme" do
before :all do
# FIXME: unsanitary because we can't clear entries from $CLASSPATH
$CLASSPATH << __dir__
end

it "can find a specific file" do
test1_files = Dir.glob("uri:classloader:/fixtures/test1.txt")
expect(test1_files[0]).to eq "uri:classloader:/fixtures/test1.txt"
expect(File.read(test1_files[0])).to eq "test1"
end

it "can find a set of files for a wildcard filename" do
test_txt_files = Dir.glob("uri:classloader:/fixtures/test*.txt")
expect(test_txt_files).to eq %w[test1 test2 test3].map { "uri:classloader:/fixtures/#{_1}.txt" }
test_txt_files.each { expect(File.read(_1)).to eq File.basename(_1).split(".").first }

test_txt_files = Dir.glob("uri:classloader:/fixtures/test?.txt")
expect(test_txt_files).to eq %w[test1 test2 test3].map { "uri:classloader:/fixtures/#{_1}.txt" }
test_txt_files.each { expect(File.read(_1)).to eq File.basename(_1).split(".").first }
end

it "can find a specific file in a double star path" do
test5_files = Dir.glob("uri:classloader:/fixtures/**/test4.txt")
expect(test5_files[0]).to eq "uri:classloader:/fixtures/testdir/test4.txt"
expect(File.read(test5_files[0])).to eq "test4"
end
end

describe "with a file: scheme" do
it "can find a specific file" do
test1_files = Dir.glob("file:#{__dir__}/fixtures/test1.txt")
expect(test1_files[0]).to eq "file:#{__dir__}/fixtures/test1.txt"
expect(File.read(test1_files[0])).to eq "test1"
end

it "can find a set of files for a wildcard filename" do
test_txt_files = Dir.glob("file:#{__dir__}/fixtures/test*.txt")
expect(test_txt_files).to eq %w[test1 test2 test3].map { "file:#{__dir__}/fixtures/#{_1}.txt" }
test_txt_files.each { expect(File.read(_1)).to eq File.basename(_1).split(".").first }

test_txt_files = Dir.glob("file:#{__dir__}/fixtures/test?.txt")
expect(test_txt_files).to eq %w[test1 test2 test3].map { "file:#{__dir__}/fixtures/#{_1}.txt" }
test_txt_files.each { expect(File.read(_1)).to eq File.basename(_1).split(".").first }
end

it "can find a specific file in a double star path" do
test5_files = Dir.glob("file:#{__dir__}/fixtures/**/test4.txt")
expect(test5_files[0]).to eq "file:#{__dir__}/fixtures/testdir/test4.txt"
expect(File.read(test5_files[0])).to eq "test4"
end
end

describe "with a jar:file: scheme" do
before :all do
tmpdir = Dir.mktmpdir
@test_files_jar = "#{tmpdir}/spec_jruby_dir_glob.jar"
system "jar cf #{@test_files_jar} -C #{__dir__} fixtures"
end

after :all do
FileUtils.rm_f @test_files_jar
end

it "can find a specific file" do
test1_files = Dir.glob("jar:file:#{@test_files_jar}!fixtures/*")
expect(test1_files[0]).to eq "jar:file:#{@test_files_jar}!fixtures/test1.txt"
expect(File.read(test1_files[0])).to eq "test1"
end

it "can find a set of files for a wildcard filename" do
test_txt_files = Dir.glob("jar:file:#{@test_files_jar}!fixtures/test*.txt")
expect(test_txt_files).to eq %w[test1 test2 test3].map { "jar:file:#{@test_files_jar}!fixtures/#{_1}.txt" }
test_txt_files.each { expect(File.read(_1)).to eq File.basename(_1).split(".").first }

test_txt_files = Dir.glob("jar:file:#{@test_files_jar}!fixtures/test?.txt")
expect(test_txt_files).to eq %w[test1 test2 test3].map { "jar:file:#{@test_files_jar}!fixtures/#{_1}.txt" }
test_txt_files.each { expect(File.read(_1)).to eq File.basename(_1).split(".").first }
end

it "can find a specific file in a double star path" do
test5_files = Dir.glob("jar:file:#{@test_files_jar}!fixtures/**/test4.txt")
expect(test5_files[0]).to eq "jar:file:#{@test_files_jar}!fixtures/testdir/test4.txt"
expect(File.read(test5_files[0])).to eq "test4"
end

it "can find a specific file in a \".\" relative path" do
test1_files = Dir.glob("jar:file:#{@test_files_jar}!./fixtures/test1.txt")
expect(test1_files[0]).to eq "jar:file:#{@test_files_jar}!./fixtures/test1.txt"
expect(File.read(test1_files[0])).to eq "test1"
end

it "treats a bare \".\" path as its own entry" do
test1_files = Dir.glob("jar:file:#{@test_files_jar}!.")
expect(test1_files[0]).to eq "jar:file:#{@test_files_jar}!."
end
end
end


1 change: 1 addition & 0 deletions spec/jruby/core/file/absolute_path_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

# This represents internal paths for files contain within jar files.
it "should return itself for 'classpath:uri:/'" do
skip("jruby/jruby#8981") if RbConfig::CONFIG['host_os']
['classpath:uri:/', 'classpath:uri:/home/me'].each do |path|
expect(File.absolute_path(path)).to eq path
end
Expand Down

Back | FazBrowse Home | New Git URL