Skip to content
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

Exclude importPaths that start with ".." #2637

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions source/dub/recipe/packagerecipe.d
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,14 @@ struct BuildSettingsTemplate {
continue;

foreach (spath; paths) {
// exclude paths outside projects' roots from recursive globbing
import std.algorithm : startsWith;
import std.path : pathSplitter;
if (spath.pathSplitter.startsWith("..".only)) {
logDiagnostic("Not globbing path outside project root: %s", spath);
continue;
}

enforce(!spath.empty, "Paths must not be empty strings.");
auto path = NativePath(spath);
if (!path.absolute) path = base_path ~ path;
Expand Down
14 changes: 14 additions & 0 deletions test/issue2637-parent-directory.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -e

. $(dirname "${BASH_SOURCE[0]}")/common.sh
cd "${CURR_DIR}/issue2637-parent-directory"
test ! -e bad || rmdir bad
mkdir -m 000 bad
trap 'rmdir bad' EXIT

(
cd pkg
$DUB run
)
Empty file.
1 change: 1 addition & 0 deletions test/issue2637-parent-directory/pkg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/pkg
4 changes: 4 additions & 0 deletions test/issue2637-parent-directory/pkg/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name "pkg"
targetType "executable"
sourceFiles "prog.d"
importPaths ".."
3 changes: 3 additions & 0 deletions test/issue2637-parent-directory/pkg/mod.di
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module pkg.mod;

enum message = "Hello";
9 changes: 9 additions & 0 deletions test/issue2637-parent-directory/pkg/prog.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module pkg.prog;

import std.stdio;
import pkg.mod;

void main()
{
writeln(message);
}