Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent Object properties to be detected as existent files by tabs.executeScript rule #1707

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
];

nonExistentFiles.forEach(async (filename) => {
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