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

Bug: "string..string" in patch notes is parsed as clickable URL #7

Open
BlacKcuD opened this issue Nov 6, 2021 · 1 comment
Open

Comments

@BlacKcuD
Copy link

BlacKcuD commented Nov 6, 2021

In the patch notes section of an arcade map overview, e.g. https://sc2arcade.com/map/2/184805/ text of the form someword..someword will be erroneously recognised as a clickable URL.

@Andrene
Copy link

Andrene commented Nov 28, 2021

Looks like its matching reURLWithScheme/reURL in the helpers file.

const reURL = /(http(s)?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/g;
const reMail = /^\S+@\S+$/;
const reURLWithScheme = /^([a-z]+:)?\/\//i;

export function formatDescription(s: string) {
    s = s.trim().replace(/\n/g, '<br>');
    s = s.replace(reURL, (substring) => {
        let href = substring;
        if (href.match(reMail)) {
            href = `mailto:${href}`;
        }
        else if (!href.match(reURLWithScheme)) {
            href = `http://${href}`;
        }
        return `<a href="${href}" target="_blank">${substring}</a>`;
    });
    return s;
}

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

No branches or pull requests

2 participants