Skip to content

Commit

Permalink
Merge eac86f3 into b67aaa1
Browse files Browse the repository at this point in the history
  • Loading branch information
ravneette committed Sep 22, 2017
2 parents b67aaa1 + eac86f3 commit a2b836f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/rules.md
Expand Up @@ -337,6 +337,8 @@ TODO: A lot of these are generated so this will need expanded with each unique c

| Done? | MsgType | Rule name | Addon type | Description | File Type | Source ref | Old Code | New Code |
| ----- | ------- | --------- | ---------- | ----------- | --------- | ---------- | -------- | -------- |

| :white_check_mark: | error | Web extension | Icons must have valid extension. | manifest.json | | null | WRONG_ICON_EXTENSION |
| :white_check_mark: | error | Web extension | JSON is not well formed. | manifest.json | | null | JSON_INVALID |
| :white_check_mark: | error | Web extension | Duplicate key in JSON. | manifest.json | | null | JSON_DUPLICATE_KEY |
| :white_check_mark: | error | Web extension | manifest_version in manifest.json is not valid. | manifest.json | | null | MANIFEST_VERSION_INVALID |
Expand Down
9 changes: 9 additions & 0 deletions src/const.js
Expand Up @@ -133,6 +133,15 @@ export const FLAGGED_FILE_EXTENSIONS = [
'.swf',
];

export const IMAGE_FILE_EXTENSIONS = [
'jpg',
'jpeg',
'webp',
'giff',
'png',
'svg',
];

// A list of magic numbers that we won't allow.
export const FLAGGED_FILE_MAGIC_NUMBERS = [
[0x4d, 0x5a], // EXE or DLL,
Expand Down
8 changes: 8 additions & 0 deletions src/messages/manifestjson.js
Expand Up @@ -165,3 +165,11 @@ export const NO_DEFAULT_LOCALE = {
See: https://mzl.la/2hjcaEE`),
file: MANIFEST_JSON,
};

export const WRONG_ICON_EXTENSION = {
code: 'WRONG_ICON_EXTENSION',
legacyCode: null,
message: _('Consider Adding another icon'),
description: sprintf('Icons Should be of type jpg, jpeg, webp, giff, png or svg.'),
file: MANIFEST_JSON,
};
4 changes: 3 additions & 1 deletion src/parsers/manifestjson.js
Expand Up @@ -7,7 +7,7 @@ import { oneLine } from 'common-tags';

import validate from 'schema/validator';
import { getConfig } from 'cli';
import { MANIFEST_JSON, PACKAGE_EXTENSION, CSP_KEYWORD_RE } from 'const';
import { MANIFEST_JSON, PACKAGE_EXTENSION, CSP_KEYWORD_RE, IMAGE_FILE_EXTENSIONS } from 'const';
import log from 'logger';
import * as messages from 'messages';
import JSONParser from 'parsers/json';
Expand Down Expand Up @@ -176,6 +176,8 @@ export default class ManifestJSONParser extends JSONParser {
if (!Object.prototype.hasOwnProperty.call(this.io.files, _path)) {
this.collector.addError(messages.manifestIconMissing(_path));
this.isValid = false;
} else if (!IMAGE_FILE_EXTENSIONS.includes(icons[size].split('.').pop().toLowerCase())) {
this.collector.addWarning(messages.WRONG_ICON_EXTENSION);
}
});
}
Expand Down
21 changes: 21 additions & 0 deletions tests/parsers/test.manifestjson.js
Expand Up @@ -739,5 +739,26 @@ describe('ManifestJSONParser', () => {
description: 'Icon could not be found at "icons/icon-64.png".',
});
});

it('adds an error if the icon does not have a valid extension', () => {
const addonLinter = new Linter({ _: ['bar'] });
const json = validManifestJSON({
icons: {
32: 'icons/icon-32.txt',
64: 'icons/icon-64.html',
},
});
const files = {
'icons/icon-32.txt': '89<PNG>thisistotallysomebinary',
'icons/icon-64.html': '89<PNG>thisistotallysomebinary',
};
const manifestJSONParser = new ManifestJSONParser(
json, addonLinter.collector, { io: { files } });
expect(manifestJSONParser.isValid).toBeTruthy();
const warnings = addonLinter.collector.warnings;
expect(warnings.length).toEqual(2);
expect(warnings[0].code).toEqual(messages.WRONG_ICON_EXTENSION.code);
expect(warnings[1].code).toEqual(messages.WRONG_ICON_EXTENSION.code);
});
});
});

0 comments on commit a2b836f

Please sign in to comment.