Skip to content

Commit

Permalink
👌 Update regex
Browse files Browse the repository at this point in the history
  • Loading branch information
amortemousque committed Apr 14, 2022
1 parent a8d22c1 commit 44a3a36
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/core/src/transport/eventBridge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('canUseEventBridge', () => {
expect(canUseEventBridge('foo.bar')).toBeTrue()
expect(canUseEventBridge('baz.foo.bar')).toBeTrue()
expect(canUseEventBridge('www.foo.bar')).toBeTrue()
expect(canUseEventBridge('www.qux.foo.bar')).toBeTrue()
})

it('should not detect when the bridge is present and the webView host is not allowed', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/transport/eventBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export function canUseEventBridge(hostname = window.location.hostname): boolean
return (
!!bridge &&
bridge.getAllowedWebViewHosts().some((host) => {
const escapedHost = host.replace(/\./g, '\\$&')
const isDomainOrSubDomain = new RegExp(`(^|.+\\.)${escapedHost}$`)
const escapedHost = host.replace(/\./g, '\\.&')
const isDomainOrSubDomain = new RegExp(`^(.+\\.)*${escapedHost}$`)
return !!isDomainOrSubDomain.exec(hostname)
})
)
Expand Down

0 comments on commit 44a3a36

Please sign in to comment.