Skip to content

Commit

Permalink
fix: Sanitize manifest propererty values before interpolation
Browse files Browse the repository at this point in the history
Fixes #2119
  • Loading branch information
Rob--W committed Apr 13, 2021
1 parent 146770f commit cba63e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cmd/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ function getPackageNameFromTemplate(
const packageName = filenameTemplate.replace(
/{([A-Za-z0-9._]+?)}/g,
(match, manifestProperty) => {
return getStringPropertyValue(manifestProperty, manifestData);
return safeFileName(
getStringPropertyValue(manifestProperty, manifestData));
}
);

Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/slashed-name/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Name w/o slash \\o/",
"description": "ends with.zip",
"version": "1",
"manifest_version": 2
}
16 changes: 16 additions & 0 deletions tests/unit/test-cmd/test.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ describe('build', () => {
);
});

it('sanitizes characters in extension name in filename from template', () => {
return withTempDir(
(tmpDir) =>
build({
sourceDir: fixturePath('slashed-name'),
artifactsDir: tmpDir.path(),
// name contains a slash. description ends with ".zip".
filename: 'prefix-{name}{description}',
})
.then((buildResult) => {
assert.match(buildResult.extensionPath,
/prefix-name_w_o_slash_o_ends_with\.zip$/);
})
);
});

it('throws an error if the filename contains a path', () => {
return withTempDir(
(tmpDir) =>
Expand Down

0 comments on commit cba63e9

Please sign in to comment.