Skip to content

Commit

Permalink
fix: Normalize default_locale before use (#1637)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob--W authored and rpl committed Jun 25, 2019
1 parent b28801a commit 805b617
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/cmd/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,12 @@ export async function defaultPackageCreator(

let extensionName: string = manifestData.name;

if (manifestData.default_locale) {
let {default_locale} = manifestData;
if (default_locale) {
default_locale = default_locale.replace(/-/g, '_');
const messageFile = path.join(
sourceDir, '_locales',
manifestData.default_locale, 'messages.json'
default_locale, 'messages.json'
);
log.debug('Manifest declared default_locale, localizing extension name');
extensionName = await getDefaultLocalizedName({
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/dashed-locale/_locales/en_US/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extensionName": {
"message": "extension with dashed locale"
}
}
6 changes: 6 additions & 0 deletions tests/fixtures/dashed-locale/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"manifest_version": 2,
"name": "__MSG_extensionName__",
"version": "1.0",
"default_locale": "en-US"
}
15 changes: 14 additions & 1 deletion tests/unit/test-cmd/test.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,20 @@ describe('build', () => {
.then((buildResult) => {
assert.match(buildResult.extensionPath,
/name_of_the_extension-1\.0\.zip$/);
return buildResult.extensionPath;
})
);
});

it('accept a dash in the default_locale field', () => {
return withTempDir(
(tmpDir) =>
build({
sourceDir: fixturePath('dashed-locale'),
artifactsDir: tmpDir.path(),
})
.then((buildResult) => {
assert.match(buildResult.extensionPath,
/extension_with_dashed_locale-1\.0\.zip$/);
})
);
});
Expand Down

0 comments on commit 805b617

Please sign in to comment.