xDimGG / node-steamapi

An object-oriented Steam API wrapper for Node.js developers.
https://www.npmjs.com/package/steamapi
178 stars 43 forks source link

Issue with regex for resolving vanity URLs #1

Closed Allen-Edd closed 6 years ago

Allen-Edd commented 6 years ago

When using the .resolve method and trying to resolve say DimGG's profile instead of getting his SteamID (76561198146931523) I get 76561197961425533. Which happened to be a profile named https. I've found that the regex is removing everything behind the first set of characters (https) instead of everything in front of the users profile name. I've been able to fix it by changing the regex but I'm not 100% certain that this is how the code is intended to work.

I replaced this

async resolve(info) {
    if (!info) throw new Error('no info provided');
    let steamID, steamURL;
    if (/^(?:\/?profiles\/)?\d{17}.*$/.test(info)) {
        steamID = info.replace(/^(?:\/?profiles\/)?(\d{17}).*$/, '$1');
    } else if (/^(?:\/?id\/)?\w{2,32}.*$/.test(info)) {
        steamURL = info.replace(/^(?:\/?id\/)?(\w{2,32}).*$/, '$1');
    } else {

With this, in SteamAPI.js

async resolve(info) {
    if (!info) throw new Error('no info provided');
    let steamID, steamURL;
    if (/(\/profiles\/)/.test(info)) {
        steamID = info.replace(/.*?(\/profiles\/)/, '');
    } else if (/(\/id\/)/.test(info)) {
        steamURL = info.replace(/.*?(\/id\/)/, '');
    } else {
xDimGG commented 6 years ago

This has been fixed in the most recent commit. My bad!