PostHog / posthog

🦔 PostHog provides open-source product analytics, session recording, feature flagging and A/B testing that you can self-host.
https://posthog.com
Other
21.55k stars 1.29k forks source link

isURL regex validation not accurate #10088

Closed samwinslow closed 2 years ago

samwinslow commented 2 years ago

Bug description

Hello again. It seems there is a bug with URL validation on the frontend.

How to reproduce

I have written a few test cases here which illustrate the bug (see frontend/src/lib/utils.test.ts for existing tests):

it('recognizes URLs propertly', () => {
        expect(isURL('https://www.posthog.com')).toEqual(true)
        expect(isURL('http://www.posthog.com')).toEqual(true)
        expect(isURL('http://www.posthog.com:8000/images')).toEqual(true)
        expect(isURL('http://localhost:8000/login?next=/insights')).toEqual(true)
        expect(isURL('http://localhost:8000/events?properties=%5B%5D')).toEqual(true)
        expect(isURL('https://apple.com/')).toEqual(true)                // works as expected
        expect(isURL('https://stripe.com')).toEqual(true)                // fails
        expect(isURL('https://spotify.com')).toEqual(true)               // fails
        expect(isURL('https://sevenapp.events/')).toEqual(true)          // fails
        expect(isURL('https://seven-stagingenv.web.app/')).toEqual(true) // fails
        expect(isURL('https://salesforce.co.uk/')).toEqual(true)         // fails
    })

Environment

Additional context

Thank you for your bug report – we love squashing them!

liyiy commented 2 years ago

hello :3 thanks for the issue, hope it's resolved? @samwinslow