@hashicorp/react-components 0.0.0-canary.96df0c1 → 0.0.0-canary.a52cc0f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { parseUrl } from '.'
|
|
2
2
|
|
|
3
3
|
describe('parseUrl', () => {
|
|
4
|
-
it('
|
|
4
|
+
it('detects hashicorp.com URLs as internal', () => {
|
|
5
5
|
const url = parseUrl('https://hashicorp.com/example')
|
|
6
6
|
expect(url.href).toBe('/example')
|
|
7
7
|
expect(url.linkType).toBe('inbound')
|
|
8
8
|
})
|
|
9
9
|
|
|
10
|
-
it('
|
|
10
|
+
it('detects URLs not containing hashicorp.com as external', () => {
|
|
11
11
|
const externalUrl = 'https://google.com/example'
|
|
12
12
|
const url = parseUrl(externalUrl)
|
|
13
13
|
expect(url.href).toBe(externalUrl)
|
|
14
14
|
expect(url.linkType).toBe('outbound')
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
it('
|
|
17
|
+
it('detects relative URLs as internal', () => {
|
|
18
18
|
const relativeUrl = '/resources'
|
|
19
19
|
const url = parseUrl(relativeUrl)
|
|
20
20
|
expect(url.href).toBe(relativeUrl)
|
|
21
21
|
expect(url.linkType).toBe('inbound')
|
|
22
22
|
})
|
|
23
23
|
|
|
24
|
-
it('
|
|
24
|
+
it('leaves URL search params intact', () => {
|
|
25
25
|
const url = parseUrl(
|
|
26
26
|
'https://hashicorp.com/resources?type=case-study&products=terraform'
|
|
27
27
|
)
|
|
@@ -26,6 +26,4 @@ export function parseUrl(url: string | undefined): {
|
|
|
26
26
|
const isRelative = (url) => url.startsWith('/')
|
|
27
27
|
const isAnchor = (url) => url.startsWith('#')
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
url.startsWith('https://hashicorp.com') ||
|
|
31
|
-
url.startsWith('https://www.hashicorp.com')
|
|
29
|
+
const isInternal = (url) => new URL(url).hostname.includes('hashicorp.com')
|