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: ensure dots in content script patterns aren't used as wildcards #17594

Merged
merged 4 commits into from Mar 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/renderer/content-scripts-injector.js
Expand Up @@ -3,11 +3,15 @@
const ipcRenderer = require('@electron/internal/renderer/ipc-renderer-internal')
const { runInThisContext } = require('vm')

const escapePattern = function (pattern) {
return pattern.replace(/[\\^$+?.()|[\]{}]/g, '\\$&')
}

// Check whether pattern matches.
// https://developer.chrome.com/extensions/match_patterns
const matchesPattern = function (pattern) {
if (pattern === '<all_urls>') return true
const regexp = new RegExp(`^${pattern.replace(/\*/g, '.*')}$`)
const regexp = new RegExp(`^${pattern.split('*').map(escapePattern).join('.*')}$`)
const url = `${location.protocol}//${location.host}${location.pathname}`
return url.match(regexp)
}
Expand Down