Skip to content

Commit 0c0aa8b

Browse files
committed
refactor: check output_dir is a subdirectory of the source dir
1 parent 21230a7 commit 0c0aa8b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

generator/lib/src/code_builder.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,16 @@ class CodeBuilder extends Builder {
112112
// need to prefix imports with as many '../' to be relative from root.
113113
final rootPath = _dir(buildStep);
114114
final outPath = _outDir(buildStep);
115-
final rootDir = Directory(rootPath);
116-
var outDir = Directory(outPath);
115+
final rootDir = Directory(rootPath).absolute;
116+
var outDir = Directory(outPath).absolute;
117117
var prefix = '';
118+
119+
if (!outDir.path.startsWith(rootDir.path)) {
120+
throw InvalidGenerationSourceError(
121+
'configured output_dir ${outDir.path} is not a '
122+
'subdirectory of the source directory ${rootDir.path}');
123+
}
124+
118125
while (outDir.path != rootDir.path) {
119126
final parent = outDir.parent;
120127
if (parent.path == outDir.path) {

0 commit comments

Comments
 (0)