Skip to content

Conversation

lionel-rowe
Copy link

Fixes #143
Fixes #142

From my comment on #143:

Current fix gives wrong capture group results, as there are more capture groups in the lookaround-supporting regex than there are in the compat-mode regex:

const OriginalRegExp = globalThis.RegExp;

class SafariRegExp extends OriginalRegExp {
    constructor(pattern, flags) {
        super(pattern, flags)
        if (String(pattern).includes('(?<=')) {
            throw new SyntaxError('idk what (?<= even means')
        }
    }
}

globalThis.RegExp = SafariRegExp

const anchorme = (await import('https://esm.sh/v135/anchorme@3.0.8')).default
console.info(
    anchorme.list(
        `https://example.xyz example.com user@email.com file:///filename.txt 192.168.1.1`,
        false,
    )
)

// expected:
[
	{ start: 0, end: 19, string: 'https://example.xyz', isURL: true, protocol: 'https://', /* ... */ },
	{ start: 20, end: 31, string: 'example.com', isURL: true, protocol: undefined, /* ... */ },
	{ start: 32, end: 46, string: 'user@email.com', isEmail: true, local: 'user', /* ... */ },
	{ start: 47, end: 67, string: 'file:///filename.txt', isFile: true, protocol: 'file:///', /* ... */ },
	{ start: 68, end: 79, string: '192.168.1.1', isURL: true, protocol: undefined, /* ... */ },	
]
// actual:
[
	{ start: 0, end: 19, string: 'https://example.xyz', reason: 'unknown' },
	{ start: 20, end: 31, string: 'example.com', reason: 'unknown' },
	{ start: 32, end: 46, string: 'user@email.com', reason: 'unknown' },
	{ start: 47, end: 67, string: 'file:///filename.txt', isURL: true, protocol: undefined, /* ... */ },
	{ start: 68, end: 79, string: '192.168.1.1', reason: 'unknown' },	
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lookbehind not supported on safari < 17 Invalid regular expression on Safari iOS < 16.4

1 participant