From 6516c9917cbc6ffa6ec9aabc01f65030dab7e308 Mon Sep 17 00:00:00 2001 From: Luca Greco Date: Fri, 15 Dec 2017 16:14:22 +0100 Subject: [PATCH] fix: prevent Object properties to be detected as existent files by tabs.executeScript rule --- .../javascript/content-scripts-file-absent.js | 2 +- .../test.content_scripts_file_absent.js | 23 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/rules/javascript/content-scripts-file-absent.js b/src/rules/javascript/content-scripts-file-absent.js index a72fac8c53a..4a83c102d90 100644 --- a/src/rules/javascript/content-scripts-file-absent.js +++ b/src/rules/javascript/content-scripts-file-absent.js @@ -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. diff --git a/tests/rules/javascript/test.content_scripts_file_absent.js b/tests/rules/javascript/test.content_scripts_file_absent.js index 228b39a431a..1d5d59a627b 100644 --- a/tests/rules/javascript/test.content_scripts_file_absent.js +++ b/tests/rules/javascript/test.content_scripts_file_absent.js @@ -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 () => {