|
1 | 1 | /* global window:true */ |
2 | | - |
3 | | -import isAbsoluteUrl from 'is-absolute-url'; |
4 | | - |
5 | 2 | import PropTypes from 'prop-types'; |
6 | 3 | import React, {Component} from 'react'; |
7 | 4 |
|
8 | | -/* event polyfill for IE https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent */ |
9 | | -function CustomEvent(event, params) { |
10 | | - // eslint-disable-next-line no-param-reassign |
11 | | - params = params || { |
12 | | - bubbles: false, |
13 | | - cancelable: false, |
14 | | - // eslint-disable-next-line no-undefined |
15 | | - detail: undefined |
16 | | - }; |
17 | | - const evt = document.createEvent('CustomEvent'); |
18 | | - evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); |
19 | | - return evt; |
| 5 | +// absolute URL check vendored from is-absolute-url |
| 6 | +// Scheme: https://tools.ietf.org/html/rfc3986#section-3.1 |
| 7 | +// Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3 |
| 8 | +const ABSOLUTE_URL_REGEX = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/; |
| 9 | + |
| 10 | +// Windows paths like `c:\` |
| 11 | +const WINDOWS_PATH_REGEX = /^[a-zA-Z]:\\/; |
| 12 | + |
| 13 | +function isAbsoluteUrl(url) { |
| 14 | + if (typeof url !== 'string') { |
| 15 | + throw new TypeError(`Expected a \`string\`, got \`${typeof url}\``); |
| 16 | + } |
| 17 | + |
| 18 | + if (WINDOWS_PATH_REGEX.test(url)) { |
| 19 | + return false; |
| 20 | + } |
| 21 | + |
| 22 | + return ABSOLUTE_URL_REGEX.test(url); |
20 | 23 | } |
21 | | -CustomEvent.prototype = window.Event.prototype; |
22 | 24 |
|
23 | 25 | function isExternalLink(external_link, href) { |
24 | 26 | if (typeof external_link === 'undefined' || external_link === null) { |
|
0 commit comments