api-query-params icon indicating copy to clipboard operation
api-query-params copied to clipboard

Error with casters and )

Open scare82 opened this issue 3 years ago • 2 comments

Hi and sorry for my poor english. I've a problem with ')' char when i try to force cast with string() or use casters with a custom function. To reproduce the issue:

  const val = aqp("key1=string(abc))");
  console.log(val);

  const val2 = aqp("key1=stringPers(abc))", {
    casters: {
      stringPers: (val: string) => val,
    },
  });
  console.log(val2);

with '(' char works very well.

A workaround seems to use castParams that works with ')' but fails with ',' (the key is converted in array with $in operator)

To reproduce:

const val3 = aqp("key1=a,b,c,)&key2=abc)", {
    castParams: {
      key1: "string",
      key2: "string",
    },
  });
  console.log(val3);

So i haven't still find a way to cast a key with ')' and ',' to simple string

Thanks for help and compliments for your package, is very useful.

Filippo

scare82 avatar May 25 '22 06:05 scare82

Hi! So to understand, you have a query param value, which contains both , and ) reserved characters, like abc,), that you'd like to be extracted as a single string?

We could probably do a PR to make the value separator character (right now ,) an option. This way you could change it to a character you are not using as part of your string (like |)? Would that work?

loris avatar Jun 02 '22 18:06 loris

Hi Loris and thanks for reply. Yes, i've a query param value that can contains both ',', ')'

We could probably do a PR to make the value separator character (right now ,) an option.

It's sound like a perfect solution for my problem

scare82 avatar Jun 06 '22 05:06 scare82