-
-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix glob expansion that includes broken symlinks #1567
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,15 @@ var ( | |
"lorem", "ipsum", | ||
"d1/e/f/g/X", "d2/e/f/g/X"} | ||
createDots = []string{".x", ".el/x"} | ||
symlinks = []struct { | ||
path string | ||
target string | ||
}{ | ||
{"d1/s-f", "f"}, | ||
{"s-d", "d2"}, | ||
{"s-d-f", "d1/f"}, | ||
{"s-bad", "bad"}, | ||
} | ||
) | ||
|
||
type globCase struct { | ||
|
@@ -28,22 +37,21 @@ type globCase struct { | |
} | ||
|
||
var globCases = []globCase{ | ||
{"*", []string{"a", "b", "c", "d1", "d2", "dX", "dXY", "lorem", "ipsum"}}, | ||
{"*", []string{"a", "b", "c", "d1", "d2", "dX", "dXY", "lorem", "ipsum", "s-bad", "s-d", "s-d-f"}}, | ||
{".", []string{"."}}, | ||
{"./*", []string{"./a", "./b", "./c", "./d1", "./d2", "./dX", "./dXY", "./lorem", "./ipsum"}}, | ||
{"./*", []string{"./a", "./b", "./c", "./d1", "./d2", "./dX", "./dXY", "./lorem", "./ipsum", "./s-bad", "./s-d", "./s-d-f"}}, | ||
{"..", []string{".."}}, | ||
{"a/..", []string{"a/.."}}, | ||
{"a/../*", []string{"a/../a", "a/../b", "a/../c", "a/../d1", "a/../d2", "a/../dX", "a/../dXY", "a/../lorem", "a/../ipsum"}}, | ||
{"a/../*", []string{"a/../a", "a/../b", "a/../c", "a/../d1", "a/../d2", "a/../dX", "a/../dXY", "a/../ipsum", "a/../lorem", "a/../s-bad", "a/../s-d", "a/../s-d-f"}}, | ||
{"*/", []string{"a/", "b/", "c/", "d1/", "d2/"}}, | ||
{"**", append(mkdirs, creates...)}, | ||
{"**", []string{"a", "a/X", "a/Y", "b", "b/X", "c", "c/Y", "d1", "d1/e", "d1/e/f", "d1/e/f/g", "d1/e/f/g/X", "d1/s-f", "d2", "d2/e", "d2/e/f", "d2/e/f/g", "d2/e/f/g/X", "dX", "dXY", "ipsum", "lorem", "s-bad", "s-d", "s-d-f"}}, | ||
{"*/X", []string{"a/X", "b/X"}}, | ||
{"**X", []string{"a/X", "b/X", "dX", "d1/e/f/g/X", "d2/e/f/g/X"}}, | ||
{"*/*/*", []string{"d1/e/f", "d2/e/f"}}, | ||
{"l*m", []string{"lorem"}}, | ||
{"d*", []string{"d1", "d2", "dX", "dXY"}}, | ||
{"d*/", []string{"d1/", "d2/"}}, | ||
{"d**", []string{"d1", "d1/e", "d1/e/f", "d1/e/f/g", "d1/e/f/g/X", | ||
"d2", "d2/e", "d2/e/f", "d2/e/f/g", "d2/e/f/g/X", "dX", "dXY"}}, | ||
{"d**", []string{"d1", "d1/e", "d1/e/f", "d1/e/f/g", "d1/e/f/g/X", "d1/s-f", "d2", "d2/e", "d2/e/f", "d2/e/f/g", "d2/e/f/g/X", "dX", "dXY"}}, | ||
{"?", []string{"a", "b", "c"}}, | ||
{"??", []string{"d1", "d2", "dX"}}, | ||
|
||
|
@@ -80,6 +88,15 @@ func testGlob(t *testing.T, abs bool) { | |
} | ||
f.Close() | ||
} | ||
for _, link := range symlinks { | ||
err := os.Symlink(link.target, link.path) | ||
if err != nil { | ||
// Creating symlinks requires a special permission on Windows. If | ||
// the user doesn't have that permission, just skip the whole test. | ||
t.Skip(err) | ||
Comment on lines
+94
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Skipping the entire test makes sense in the TestPath_Symlink function this is borrowed from, because that entire test is about symlinks. It makes much less sense here, it makes a large part of the globbing code untested on Windows. A better strategy is to just create the symlinks as ordinary files on Windows. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I would argue that both sets of tests should fail if unable to create a symlink on Windows. The CI environment should always have that capability enabled. And anyone running these tests on their local system should also have the capability enabled. The question is whether, and how, to test the behavior on Windows when the symlink capability isn't enabled. |
||
} | ||
} | ||
|
||
for _, tc := range globCases { | ||
pattern := tc.pattern | ||
if abs { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fix but it's also a breaking change - symlinks to directories will now be treated as files, not directories. This breaking change is fine for me - among other things it avoids infinite recursions when expanding
**
symlinks introduce loops in the FS tree. But it should be documented as such.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another good point but the existing behavior is flat out wrong and it's unclear how to document the change in behavior.