ascorbic / unpic

Universal image CDN translator
https://unpic.pics/lib
283 stars 31 forks source link

getNumericParam adds 1 to value #38

Closed tiptenbrink closed 1 year ago

tiptenbrink commented 1 year ago

This is your code for getNumericParam which is used to parse URLs of some CDNs like bunny and wordpress:

export const getNumericParam = (url: URL, key: string) => {
  const value = Number(url.searchParams.get(key));
  return isNaN(value) ? undefined : value + 1;
};

I noticed this as I wanted to add CDN support for KeyCDN and was designing tests. Why is 1 added to the value of the parameter? This is not caught in any tests as none of the CDNs which use this function to parse URLs actually test their URL parsers.

I also admit I'm unsure for what the URL parsers are designed to accomplish. This would help me to know what I need to add.

Thanks!

ascorbic commented 1 year ago

Oh, good spot! I think I added that in development and never removed it!

brianbento commented 1 year ago

@ascorbic I put in a pull request for a new transformer. Fixed the error in there as well.

ascorbic commented 1 year ago

Fixed in #38