Skip to content

Regex does not handle local folders with a dot in the name #14

@toja83

Description

@toja83

If I have a folder name with a dot, like "/Users/tommie/Git/Github.com/my-project/my-file.mp3", then it is recognized as a url and tries to find a youtube video by id instead, which of course will fail.

I played around a bit with the regex and tried multiple urls + linux/unix and windows folders with dots and it seem to work as expected with my proposed fix below (do not allow any slash before the url, by this in the start: ^(?!\/)):

Today:
const urlRe = /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)/g

Replace with:
const urlRe = /^(?!\/)(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)/g

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions