GithubHelp home page GithubHelp logo

Comments (3)

rhysburnie avatar rhysburnie commented on May 25, 2024

I'm no regExp expert I was just going by this for rough equiv of look behind https://stackoverflow.com/a/74994273/738957
This was crashing our entire app, if this fix has a side effect on some anchorme links its preferable over an entire crash.
However if there is a better fix would be good to know.

from anchorme.js.

alexcorvi avatar alexcorvi commented on May 25, 2024

Please check the latest version 3.0.7

from anchorme.js.

lionel-rowe avatar lionel-rowe commented on May 25, 2024

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' },	
]

I'll have a PR up with a fix shortly — I think with the fix, reason: "unknown" can also be removed entirely as it should never occur.

from anchorme.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google âĪïļ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.