-
-
Notifications
You must be signed in to change notification settings - Fork 730
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
Exclude the value of a certain key, from getting encoded #491
Comments
one simple solution would be to include the prefix here as well Lines 123 to 129 in 981ce09
to this: if (isNonNullishPrimitive(obj) || utils.isBuffer(obj)) {
if (encoder) {
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset, 'key', format, undefined);
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset, 'value', format, prefix))];
}
return [formatter(prefix) + '=' + formatter(String(obj))];
} without introducing any breaking changes to the library |
Can you explain your use case? |
@ljharb sure I know this is a very rare use case, but adding this simple parameter to custom encoder solved my problem. And it's not going to introduce a breaking change This will give developers a new way to customize the behavior of the qs |
Can you provide an example token, so i can see the format involved? |
Definitely first request will return this payload:
and I have to send it as it is, which means a request like this
using this code const listOfExcludedKeys = ['nextToken'];
const str = stringify(params, {
encoder(str, defaultEncoder, charset, type, format, prefix) {
// parameters like 'nextToken' are already encoded
// we need to skip them.
if (prefix && listOfExcludedKeys.includes(prefix)) return str;
return defaultEncoder(str, defaultEncoder, charset);
},
}); but if i disable my customer encoder, this will be the result:
it's getting double encoded |
Could you decode the key and then when qs re-encodes it, it'd be what you want? Perhaps using the |
That was my first solution @ljharb, and it was working perfectly |
It's useful to note the current workaround, at least. Presumably this API is sending a pre-encoded value in the response - why are they doing that? Generally I'd expect an API to only use encoding on the outer level of a response. |
Yep, what you are saying is totally correct, but sometimes we are dealing with external APIs that we have no control over. having a library that lets me customize the functionality is great |
Is there a way to exclude the value of a key from getting encoded?
I tried using a custom encode function, but that function runs on value and key separately, and there is no way to understand the key of a certain value inside it
The text was updated successfully, but these errors were encountered: