Skip to content

Commit

Permalink
fix: prevent Object properties to be detected as existent files by ta…
Browse files Browse the repository at this point in the history
…bs.executeScript rule
  • Loading branch information
rpl committed Dec 15, 2017
1 parent 9ecbb53 commit bfe99f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/rules/javascript/content-scripts-file-absent.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default {
}
const normalizedName = normalizePath(fileValue);
// If file exists then we are good.
if (normalizedName in existingFiles) {
if (Object.prototype.hasOwnProperty.call(existingFiles, normalizedName)) {
return;
}
// File not exists report an issue.
Expand Down
23 changes: 16 additions & 7 deletions tests/rules/javascript/test.content_scripts_file_absent.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@ function createJsScanner(code, validatedFilename, existingFiles = {}) {

describe('content_scripts_file_absent', () => {
it('should show an error when content script is missing', async () => {
const code = `browser.tabs.executeScript({ file: '/content_scripts/absentFile.js' });`;
const fileRequiresContentScript = 'file-requires-content-script.js';
const jsScanner = createJsScanner(code, fileRequiresContentScript);
const nonExistentFiles = [
'absentFile.js',

const { linterMessages } = await jsScanner.scan();
expect(linterMessages.length).toEqual(1);
expect(linterMessages[0].code).toEqual(CONTENT_SCRIPT_NOT_FOUND.code);
expect(linterMessages[0].type).toEqual(VALIDATION_ERROR);
// Check that the rule is not detecting Object properties as existent files.
'constructor',
];

for (const filename of nonExistentFiles) {
const code = `browser.tabs.executeScript({ file: '${filename}' });`;
const fileRequiresContentScript = 'file-requires-content-script.js';
const jsScanner = createJsScanner(code, fileRequiresContentScript);

const { linterMessages } = await jsScanner.scan();
expect(linterMessages.length).toEqual(1);
expect(linterMessages[0].code).toEqual(CONTENT_SCRIPT_NOT_FOUND.code);
expect(linterMessages[0].type).toEqual(VALIDATION_ERROR);
}
});

it('should not show an error when content script file exists', async () => {
Expand Down

0 comments on commit bfe99f2

Please sign in to comment.