diff --git a/src/excmds.ts b/src/excmds.ts index 6426de24..f7ed1ccc 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -3502,19 +3502,19 @@ export function autocmd(event: string, url: string, ...excmd: string[]) { /** * Automatically open a domain and all its subdomains in a specified container. * + * __NB:__ You should use this command with an -s (sane mode) or -u (URL mode) flag. Usage without a flag uses an incorrect regular expression which may cause weird behaviour and has been left in for compatibility reasons. + * * This function accepts a `-u` flag to treat the pattern as a URL rather than a domain. - * For example: `autocontain -u ^https?://[^/]*youtube\.com/ google` is equivalent to `autocontain youtube\.com google` + * For example: `autocontain -u ^https?://([^/]*\\.|)youtube\\.com/ google` is equivalent to `autocontain -s youtube\.com google` * * For declaring containers that do not yet exist, consider using `auconcreatecontainer true` in your tridactylrc. - * This allows tridactyl to automatically create containers from your autocontain directives. Note that they will be random icons and colors. - * - * __NB: This is an experimental feature, if you encounter issues please create an issue on GitHub.__ + * This allows Tridactyl to automatically create containers from your autocontain directives. Note that they will be random icons and colors. * * The domain is passed through as a regular expression so there are a few gotchas to be aware of: - * * Unescaped periods will match *anything*. `autocontain google.co.uk work` will match `google!co$uk`. Escape your periods or accept that you might get some false positives. - * * You can use regex in your pattern. `autocontain google\.(co\.uk|com) work` will match either `google.co.uk` or `google.com`. + * * Unescaped periods will match *anything*. `autocontain -s google.co.uk work` will match `google!co$uk`. Escape your periods [twice](https://javascript.info/regexp-escaping#new-regexp) (i.e. `\\.` rather than `\.`) or accept that you might get some false positives. + * * You can use regex in your pattern. `autocontain -s google\\.(co\\.uk|com) work` will match either `google.co.uk` or `google.com`. * - * This *should* now peacefully coexist with the Temporary Containers and Multi-Account Containers addons. Do not trust this claim. If a fight starts the participants will try to open infinite tabs. It is *strongly* recommended that you use a tridactylrc so that you can abort a sorceror's-apprentice scenario by killing firefox, commenting out all of autocontainer directives in your rc file, and restarting firefox to clean up the mess. There are a number of strange behaviors resulting from limited coordination between extensions. Redirects can be particularly surprising; for example, with `:autocontain will-redirect.example.org example` set and `will-redirect.example.org` redirecting to `redirected.example.org`, navigating to `will-redirect.example.org` will result in the new tab being in the `example` container under some conditions and in the `firefox-default` container under others. + * This *should* now peacefully coexist with the Temporary Containers and Multi-Account Containers addons. Do not trust this claim. If a fight starts the participants will try to open infinite tabs. It is *strongly* recommended that you use a tridactylrc so that you can abort a sorceror's-apprentice scenario by killing firefox, commenting out all of autocontainer directives in your rc file, and restarting firefox to clean up the mess. There are a number of strange behaviors resulting from limited coordination between extensions. Redirects can be particularly surprising; for example, with `:autocontain -s will-redirect.example.org example` set and `will-redirect.example.org` redirecting to `redirected.example.org`, navigating to `will-redirect.example.org` will result in the new tab being in the `example` container under some conditions and in the `firefox-default` container under others. * * @param args a regex pattern to match URLs followed by the container to open the URL in. */ @@ -3523,15 +3523,16 @@ export function autocontain(...args: string[]) { if (args.length === 0) throw new Error("Invalid autocontain arguments.") const urlMode = args[0] === "-u" - if (urlMode) { + const saneMode = args[0] === "-s" + if (urlMode || saneMode) { args.splice(0, 1) } - if (args.length !== 2) throw new Error("syntax: autocontain [-u] pattern container") + if (args.length !== 2) throw new Error("syntax: autocontain [-{u,s}] pattern container") let [pattern, container] = args if (!urlMode) { - pattern = `^https?://[^/]*${pattern}/` + pattern = saneMode ? `^https?://([^/]*\\.|)${pattern}/` : `^https?://[^/]*${pattern}/` } return config.set("autocontain", pattern, container) diff --git a/src/lib/config.ts b/src/lib/config.ts index 9ac13d83..da7d9d94 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -1504,7 +1504,7 @@ export async function update() { unset("autocontain") if (autocontain !== undefined) { Object.entries(autocontain).forEach(([domain, container]) => { - set("autocontain", `^https?://[^/]*${domain}/`, container) + set("autocontain", `^https?://([^/]*\\.|)*${domain}/`, container) }) } set("configversion", "1.8")