Skip to content

Commit 4886261

Browse files
authored
Fix regex lookback crashing older browsers (#6571)
1 parent 3563d95 commit 4886261

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/components/MDX/ErrorDecoder.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ function replaceArgs(
1818
/**
1919
* Sindre Sorhus <https://sindresorhus.com>
2020
* Released under MIT license
21-
* https://github.com/sindresorhus/linkify-urls/blob/edd75a64a9c36d7025f102f666ddbb6cf0afa7cd/index.js#L4C25-L4C137
21+
* https://github.com/sindresorhus/linkify-urls/blob/b2397096df152e2f799011f7a48e5f73b4bf1c7e/index.js#L5C1-L7C1
2222
*
2323
* The regex is used to extract URL from the string for linkify.
2424
*/
25-
const urlRegex =
26-
/((?<!\+)https?:\/\/(?:www\.)?(?:[-\w.]+?[.@][a-zA-Z\d]{2,}|localhost)(?:[-\w.:%+~#*$!?&/=@]*?(?:,(?!\s))*?)*)/g;
25+
const urlRegex = () =>
26+
/((?:https?(?::\/\/))(?:www\.)?(?:[a-zA-Z\d-_.]+(?:(?:\.|@)[a-zA-Z\d]{2,})|localhost)(?:(?:[-a-zA-Z\d:%_+.~#!?&//=@]*)(?:[,](?![\s]))*)*)/g;
2727

2828
// When the message contains a URL (like https://fb.me/react-refs-must-have-owner),
2929
// make it a clickable link.
3030
function urlify(str: string): React.ReactNode[] {
31-
const segments = str.split(urlRegex);
31+
const segments = str.split(urlRegex());
3232

3333
return segments.map((message, i) => {
3434
if (i % 2 === 1) {

0 commit comments

Comments
 (0)