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

Don't add empty queryString to URL #114

Closed
xpuu opened this issue Aug 6, 2021 · 1 comment
Closed

Don't add empty queryString to URL #114

xpuu opened this issue Aug 6, 2021 · 1 comment
Labels

Comments

@xpuu
Copy link

xpuu commented Aug 6, 2021

Hi, once again thanks for your great work. I use this lib in our 3D Printer UI already for 3 years and love it. I'm used to do nasty things with her e.g.:

// id = undefined  - all printers
// id = string     - specific printer
// id = string[]   - specific printers
function getPrinterState(id) {
     return wretcher(api).query(id && { id }).get().json(res => typeof id === string ? res[id] : res)
}

But, as my overly attentive colleague pointed out, when you run .query(false) wretcher adds '?' or '&', which might confuse the api server.

I propose to add simple check to appendQueryParams on line 325, something like:

const split = url.split("?")

if (!queryString) 
    return replace ? split[0] : url

if (replace || split.length < 2)
    return split[0] + "?" + queryString

return url + "&" + queryString
@elbywan
Copy link
Owner

elbywan commented Aug 6, 2021

Hey @xpuu,

Hi, once again thanks for your great work. I use this lib in our 3D Printer UI already for 3 years and love it.

❤️

But, as my overly attentive colleague pointed out, when you run .query(false) wretcher adds '?' or '&', which might confuse the api server.

Thanks for reporting the issue! I've just pushed commit 15464a8 containing the fix. I'll also make a a patch release in a few minutes 📦.

@elbywan elbywan added the bug label Aug 6, 2021
@elbywan elbywan closed this as completed Aug 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants