Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safari compat fix (capture group preserving version) #146

Open
wants to merge 3 commits into
base: gh-pages
Choose a base branch
from

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/[email protected]')).default
console.info(
    anchorme.list(
        `https://example.xyz example.com [email protected] 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: '[email protected]', 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: '[email protected]', 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