-
Notifications
You must be signed in to change notification settings - Fork 11.9k
fix(@angular/build): prevent deleting parent directories of project root #32873
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
Open
pradhankukiran
wants to merge
5
commits into
angular:main
Choose a base branch
from
pradhankukiran:fix-delete-output-dir-ancestor-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+76
−2
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4886930
fix(@angular/build): prevent deleting parent directories of project root
pradhankukiran 6c745cc
fixup! fix(@angular/build): prevent deleting parent directories of pr…
pradhankukiran a2b1fab
fixup! fix(@angular/build): prevent deleting parent directories of pr…
alan-agius4 9d3f5d4
fix(@angular/build): handle Windows absolute paths in output dir check
pradhankukiran 3a6d97a
fixup! fix(@angular/build): prevent deleting parent directories of pr…
pradhankukiran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/angular/build/src/utils/delete-output-dir_spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import { mkdir, mkdtemp, readdir, writeFile } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
| import { deleteOutputDir } from './delete-output-dir'; | ||
|
|
||
| describe('deleteOutputDir', () => { | ||
| let root: string; | ||
|
|
||
| beforeEach(async () => { | ||
| root = await mkdtemp(join(tmpdir(), 'ng-test-')); | ||
| }); | ||
|
|
||
| it('should throw when output path is the project root', async () => { | ||
| await expectAsync(deleteOutputDir(root, '.')).toBeRejectedWithError( | ||
| /MUST not be the workspace root directory/, | ||
| ); | ||
| }); | ||
|
|
||
| it('should throw when output path is a parent of the project root', async () => { | ||
| await expectAsync(deleteOutputDir(root, '..')).toBeRejectedWithError( | ||
| /MUST not be a parent of the workspace root directory/, | ||
| ); | ||
| }); | ||
|
|
||
| it('should throw when output path is a grandparent of the project root', async () => { | ||
| await expectAsync(deleteOutputDir(root, '../..')).toBeRejectedWithError( | ||
| /MUST not be a parent of the workspace root directory/, | ||
| ); | ||
| }); | ||
|
|
||
| it('should not throw when output path is a child of the project root', async () => { | ||
| const outputDir = join(root, 'dist'); | ||
| await mkdir(outputDir, { recursive: true }); | ||
| await writeFile(join(outputDir, 'old-file.txt'), 'content'); | ||
|
|
||
| await expectAsync(deleteOutputDir(root, 'dist')).toBeResolved(); | ||
| }); | ||
|
|
||
| it('should delete contents of a valid output directory', async () => { | ||
| const outputDir = join(root, 'dist'); | ||
| await mkdir(outputDir, { recursive: true }); | ||
| await writeFile(join(outputDir, 'old-file.txt'), 'content'); | ||
|
|
||
| await deleteOutputDir(root, 'dist'); | ||
|
|
||
| const entries = await readdir(outputDir); | ||
| expect(entries.length).toBe(0); | ||
| }); | ||
|
|
||
| it('should not throw when output directory does not exist', async () => { | ||
| await expectAsync(deleteOutputDir(root, 'nonexistent')).toBeResolved(); | ||
| }); | ||
|
|
||
| it('should not throw when output path is an absolute path outside the project', async () => { | ||
| const externalDir = await mkdtemp(join(tmpdir(), 'ng-test-external-')); | ||
| await writeFile(join(externalDir, 'old-file.txt'), 'content'); | ||
|
|
||
| await expectAsync(deleteOutputDir(root, externalDir)).toBeResolved(); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.