Skip to content

Commit 14b3743

Browse files
clydinBrocco
authored andcommitted
fix(@angular/cli): normalize asset windows paths
1 parent 5f73a75 commit 14b3743

File tree

1 file changed

+11
-5
lines changed
  • packages/@angular/cli/models/webpack-configs

1 file changed

+11
-5
lines changed

packages/@angular/cli/models/webpack-configs/common.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,21 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
8383
asset = typeof asset === 'string' ? { glob: asset } : asset;
8484
// Add defaults.
8585
// Input is always resolved relative to the appRoot.
86-
asset.input = path.resolve(appRoot, asset.input || '');
86+
asset.input = path.resolve(appRoot, asset.input || '').replace(/\\/g, '/');
8787
asset.output = asset.output || '';
8888
asset.glob = asset.glob || '';
8989

9090
// Prevent asset configurations from writing outside of the output path, except if the user
9191
// specify a configuration flag.
9292
// Also prevent writing outside the project path. That is not overridable.
93-
const fullOutputPath = path.resolve(buildOptions.outputPath, asset.output);
94-
if (!fullOutputPath.startsWith(path.resolve(buildOptions.outputPath))) {
95-
if (!fullOutputPath.startsWith(projectRoot)) {
93+
const absoluteOutputPath = path.resolve(buildOptions.outputPath);
94+
const absoluteAssetOutput = path.resolve(absoluteOutputPath, asset.output);
95+
const outputRelativeOutput = path.relative(absoluteOutputPath, absoluteAssetOutput);
96+
97+
if (outputRelativeOutput.startsWith('..') || path.isAbsolute(outputRelativeOutput)) {
98+
99+
const projectRelativeOutput = path.relative(projectRoot, absoluteAssetOutput);
100+
if (projectRelativeOutput.startsWith('..') || path.isAbsolute(projectRelativeOutput)) {
96101
const message = 'An asset cannot be written to a location outside the project.';
97102
throw new SilentError(message);
98103
}
@@ -106,7 +111,8 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
106111
}
107112

108113
// Prevent asset configurations from reading files outside of the project.
109-
if (!asset.input.startsWith(projectRoot)) {
114+
const projectRelativeInput = path.relative(projectRoot, asset.input);
115+
if (projectRelativeInput.startsWith('..') || path.isAbsolute(projectRelativeInput)) {
110116
const message = 'An asset cannot be read from a location outside the project.';
111117
throw new SilentError(message);
112118
}

0 commit comments

Comments
 (0)