Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Dir resolves symlinks #1322

Merged
merged 2 commits into from

2 participants

@lucasallan
Collaborator

Fixing #1036

@enebo enebo merged commit 1080132 into from
@enebo
Owner

Thanks for your fix and patience :)

@lucasallan
Collaborator

@enebo No problem at all. I'm loving to contribute with JRuby :D

@enebo enebo modified the milestone: JRuby 1.7.10, JRuby 1.7.11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 10, 2013
  1. @lucasallan
  2. @lucasallan

    Fixing issue

    lucasallan authored
This page is out of date. Refresh to see the latest.
View
20 core/src/main/java/org/jruby/util/Dir.java
@@ -40,6 +40,7 @@
import jnr.posix.JavaSecuredFile;
import org.jruby.platform.Platform;
+import java.io.IOException;
/**
* This class exists as a counterpart to the dir.c file in
@@ -764,7 +765,7 @@ private static int glob_helper(String cwd, byte[] bytes, int begin, int end, int
} else {
st = new JavaSecuredFile(cwd, newStringFromUTF8(buf.getUnsafeBytes(), buf.getBegin(), buf.getRealSize()));
}
- if(st.isDirectory() && !".".equals(dirp[i]) && !"..".equals(dirp[i])) {
+ if(!isResolvedSymlink(st) && st.isDirectory() && !".".equals(dirp[i]) && !"..".equals(dirp[i])) {
int t = buf.getRealSize();
buf.append(SLASH);
buf.append(DOUBLE_STAR);
@@ -912,4 +913,21 @@ private static String newStringFromUTF8(byte[] buf, int offset, int len) {
private static String newStringFromUTF8(byte[] buf) {
return RubyEncoding.decodeUTF8(buf);
}
+
+ private static boolean isResolvedSymlink(File st) {
+ try {
+ File canon;
+ if (st.getParent() == null) {
+ canon = st;
+ } else {
+ File canonDir;
+ canonDir = st.getParentFile().getCanonicalFile();
+
+ canon = new File(canonDir, st.getName());
+ }
+ return !canon.getCanonicalFile().equals(canon.getAbsoluteFile());
+ } catch (IOException e) {
+ return false;
+ }
+ }
}
View
13 test/mri/ruby/test_dir.rb
@@ -242,4 +242,17 @@ def test_home
ENV["LOGDIR"] = env_logdir
end
+ def test_symlinks_not_resolved
+ Dir.mktmpdir do |dirname|
+ FileUtils.cd(dirname) do
+ FileUtils.mkdir_p('some-dir')
+ File.write('some-dir/foo', 'some content')
+ File.symlink('some-dir', 'dir-symlink')
+
+ assert_equal [ 'dir-symlink', 'some-dir' ], Dir['*'].sort
+ assert_equal [ 'dir-symlink', 'some-dir', 'some-dir/foo' ], Dir['**/*'].sort
+ end
+ end
+ end
+
end
Something went wrong with that request. Please try again.