Skip to content

Commit ca08c14

Browse files
committed
Fixing a bug which caused wrong directory names in archive
Because the asset paths were not normalized, in some cases directories called '.' were inside the WAR archive
1 parent 984d5f3 commit ca08c14

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/WebpackWarPlugin.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,36 @@ describe('WebpackWarPlugin', function () {
144144
assert.calledWith(spyAppend, resolve((compiler as any).options.output.path, asset), { name: asset }));
145145
});
146146

147+
it('Should normalize asset paths', function () {
148+
const ArchiverDummy = {
149+
append: (() => null),
150+
pipe: (() => null),
151+
on: (() => null),
152+
finalize: (() => null)
153+
};
154+
const spyAppend = spy(ArchiverDummy, 'append');
155+
156+
const assets = {
157+
'./asset1.txt': {},
158+
'./assets/./asset2.txt': {}
159+
};
160+
161+
compilation.assets = assets;
162+
163+
const plugin = new WebpackWarPlugin({ archiveName: 'Test' });
164+
(plugin as any).archiver = (() => ArchiverDummy);
165+
plugin.apply(compiler);
166+
167+
assert.calledWith(spyAppend,
168+
resolve((compiler as any).options.output.path, Object.getOwnPropertyNames(assets)[0]),
169+
{ name: 'asset1.txt' }
170+
);
171+
assert.calledWith(spyAppend,
172+
resolve((compiler as any).options.output.path, Object.getOwnPropertyNames(assets)[1]),
173+
{ name: 'assets/asset2.txt' }
174+
);
175+
});
176+
147177
it('Should add the WEB-INF folder to the archive', function () {
148178
const ArchiverStub = {
149179
append: (() => null),

src/WebpackWarPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class WebpackWarPlugin implements Plugin {
4242

4343
Object.getOwnPropertyNames(compilation.assets).forEach(asset => {
4444
const srcPath = resolve(outputPath, asset);
45-
archive.append(srcPath, { name: asset });
45+
archive.append(srcPath, { name: normalize(asset) });
4646
});
4747

4848
additionalElements.forEach(({ path, destPath }) => {

0 commit comments

Comments
 (0)