-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correct bug in
isStaging
method. (#1125)
This PR corrects a bug in the `isStaging` method. If you were referred to a Production site from a Staging link, `isStaging` would incorrectly report `true`. This is because the `includes` check on the `href` would catch the Staging `referrerPageUrl`. Simply comparring `window.location.hostname` instead of `window.location.href` fixes this. I also did some code cleanup in this method and its test suite. J=SLAP-2546 TEST=auto
- Loading branch information
1 parent
f87864a
commit b3d626f
Showing
6 changed files
with
228 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
import escapeStringRegexp from 'escape-string-regexp'; | ||
|
||
/** | ||
* Determines whether the current url is staging or production. | ||
*/ | ||
export function isStaging(stagingDomains) { | ||
const defaultStagingDomains = ['127.0.0.1', 'localhost', 'office.yext.com']; | ||
const _stagingDomains = defaultStagingDomains.concat(stagingDomains); | ||
const currentUrl = window.location.href; | ||
return _stagingDomains.some(domain => currentUrl.includes(domain)); | ||
const _stagingDomains = stagingDomains | ||
? defaultStagingDomains.concat(stagingDomains) | ||
: defaultStagingDomains; | ||
const currentDomain = window.location.hostname; | ||
|
||
return _stagingDomains.some(domain => { | ||
const regexEscapedDomain = escapeStringRegexp(domain); | ||
// The RFC for subdomains says they can contain a maximum of 63 characters. The leading and trailing characters must be alpha numeric. | ||
const isSubdomainRegex = new RegExp(`[A-Za-z0-9]?[A-Za-z0-9\-]{0,61}[A-Za-z0-9]?\.${regexEscapedDomain}`); | ||
|
||
return domain === currentDomain || isSubdomainRegex.test(currentDomain); | ||
}); | ||
} |
Oops, something went wrong.