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

CLI: Don't allow root directory as static dir #14068

Merged
merged 3 commits into from
Mar 18, 2021
Merged
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
4 changes: 4 additions & 0 deletions lib/core-server/src/build-static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export async function buildStaticStandalone(options: CLIOptions & LoadOptions &
throw new Error("Won't remove current directory. Check your outputDir!");
}

if (options.staticDir?.includes('/')) {
throw new Error("Won't copy root directory. Check your staticDirs!");
}

options.outputDir = path.isAbsolute(options.outputDir)
? options.outputDir
: path.join(process.cwd(), options.outputDir);
Expand Down
19 changes: 15 additions & 4 deletions lib/core-server/src/core-presets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,26 @@ describe('dev cli flags', () => {
...cliOptions,
outputDir,
};
beforeEach(() => {
jest.clearAllMocks();
cache.clear();
});

it('production mode', async () => {
expect.assertions(1);
await expect(buildStaticStandalone(optionsWithInvalidDir)).rejects.toThrow(
expectedErrorMessage
);
});
});

describe('Invalid staticDir must throw: root directory /', () => {
const optionsWithInvalidStaticDir = {
...cliOptions,
staticDir: ['/'],
};

it('production mode', async () => {
expect.assertions(1);
await expect(buildStaticStandalone(optionsWithInvalidStaticDir)).rejects.toThrow(
"Won't copy root directory. Check your staticDirs!"
);
});
});
});