node-qbittorrent-api-v2 icon indicating copy to clipboard operation
node-qbittorrent-api-v2 copied to clipboard

Update plainify regex to work with numbers

Open wbio opened this issue 4 years ago • 1 comments

I was trying to update the global speed limit on qBittorrent (setGlobalDownloadLimit) and got a 400 error. I did some digging and it looks like the problem is in the RegEx within the plainify method that converts the parameters object to key/value pairs. Right now the RegEx is looking for values within quotes:

str = str.replace(/"([^"]*)":"([^"]*)",?/g, '$1=$2&')

Since the global speed limit requires a number (and therefore isn't surrounded by quotes in JSON), this doesn't get replaced and formatted and str winds up looking like "limit":10240000 rather than limit=10240000.

This PR makes the quotes around the field value optional so that both numbers and strings get captured and formatted correctly.

Here's the old RegEx and here's the new RegEx.

wbio avatar Oct 07 '21 21:10 wbio

Hi @wbio, thank you for your contribution. I just merged another PR that changes the planify method. Can you let me know if this works correctly for you now or update your PR? Thanks!

flowbe avatar Feb 03 '22 12:02 flowbe