sc2-arcade-watcher / issue-tracker

1 stars 0 forks source link

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

Open BlacKcuD opened 2 years ago

BlacKcuD commented 2 years ago

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 commented 2 years ago

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;
}