Fix referrer RegEx for permanent version redirect (#3864)
This commit is contained in:
parent
6e144e9f7c
commit
3654b693e3
@ -3,7 +3,7 @@ import { getActions } from '../global';
|
||||
import { PRODUCTION_HOSTNAME, WEB_VERSION_BASE } from '../config';
|
||||
import { clearWebsync } from './websync';
|
||||
|
||||
const SEARCH_ENGINE_REFERRERS = ['google', 'bing', 'duckduckgo', 'ya', 'yandex'];
|
||||
const SEARCH_ENGINE_REGEX = /(^|\.)(google|bing|duckduckgo|ya|yandex)\./i;
|
||||
// Handled by the legacy version. Cannot be updated
|
||||
const PERMANENT_VERSION_KEY = 'kz_version';
|
||||
const AVAILABLE_VERSIONS = ['Z', 'K'] as const;
|
||||
@ -34,7 +34,10 @@ export function checkAndAssignPermanentWebVersion() {
|
||||
if (window.location.hostname !== PRODUCTION_HOSTNAME) return;
|
||||
|
||||
const referrer = document.referrer.toLowerCase();
|
||||
if (!SEARCH_ENGINE_REFERRERS.some((engine) => referrer.match(`(\\/\\/:|\\.)${engine}\\.`))) return;
|
||||
if (!referrer) return;
|
||||
try {
|
||||
const isSearchEngine = new URL(referrer).host.match(SEARCH_ENGINE_REGEX);
|
||||
if (!isSearchEngine) return;
|
||||
|
||||
const currentVersion = getPermanentWebVersion();
|
||||
if (currentVersion) {
|
||||
@ -54,4 +57,7 @@ export function checkAndAssignPermanentWebVersion() {
|
||||
}
|
||||
|
||||
switchPermanentWebVersion('K');
|
||||
} catch (e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user