lisaogren / url-composer

Building dynamic URLs

Home Page:https://rascarlito.github.io/url-composer/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

url params parsed incorrectly

yzpaul opened this issue · comments

  uu = url.build({
    host: "https://www.google.com",
    path: "(/:rsc)/:endpoint",
    params: urlparam: { endpoint: 'name' },
    query: { '$filter': 'xyz' },
  });

expected: https://www.google.com/name?$filter=xyz

got: https://www.google.com/name/:endpoint?$filter=xyz
^ note the :endpoint in my end result

Issue appears to be related to how replaceArgs() picks which param to replace. It does a regex match, then just replaces things one at a time, based on the param array. If there is no value in the param array that matches, the next param is used

A (not ideal) work around for this SPECIFIC issue is to make all params dynamic, which causes :endpoint to be dropped before returning.