Skip to content

Conversation

genomics-geek
Copy link
Contributor

@genomics-geek genomics-geek commented Mar 6, 2019

Some of our GraphQL IDs had = in their value, therefore splitting on = creates issues - unless we split by the 1st occurrence.

For example: ?testCode_In=VGVzdENvZGVOb2RlOjQ= will be parsed as: {testCode_In: "VGVzdENvZGVOb2RlOjQ"}. This leads to confusion and inaccurate search terms.

This has resolved the issue for us.

index.js Outdated

for (const param of input.split('&')) {
let [key, value] = param.replace(/\+/g, ' ').split('=');
let [key, value] = param.replace(/\+/g, ' ').split(/\=(.+)/); // eslint-disable-line no-useless-escape
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESLint is correct. You don't have to escape =.

Copy link
Contributor Author

@genomics-geek genomics-geek Mar 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sindresorhus - yup I know, but then I get a different ESLint error no-div-regex Yup I will add a test. Also, it seems to fail other tests now, so I have to look into it

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok. Better to ignore the no-div-regex rule.

@sindresorhus
Copy link
Owner

Can you add a test?

@genomics-geek
Copy link
Contributor Author

I added tests and replaced the regex with a replace().split() - not as nice as regex, but it avoids adding extra element to the split. Let me know what you think @sindresorhus

index.js Outdated

for (const param of input.split('&')) {
let [key, value] = param.replace(/\+/g, ' ').split('=');
let [key, value] = param.replace(/\+/g, ' ').replace('=', '<**>').split('<**>');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just ran into the same issue. This is the alternative I used for a fix https://github.com/cam-perry/query-string/commit/b65a53b55ae7a8825d62af757a587d365ba7e3b7:

const i = param.indexOf("=");
let key = param.slice(0, i);
let value = param.slice(i+1);

@MatheusFelipe
Copy link

We're also experiencing this issue. When will the fix be merged?

index.js Outdated

for (const param of input.split('&')) {
let [key, value] = param.replace(/\+/g, ' ').split('=');
let [key, value] = param.replace(/\+/g, ' ').replace('=', '<**>').split('<**>');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous regex was better. This is risky as it will fail if the query string actually contains <**>, even if unlikely.

@sindresorhus
Copy link
Owner

You can use my https://github.com/sindresorhus/split-on-first module.

Some of our GraphQL IDs had `=` in their value, therefore splitting on `=` creates issues - unless we split by the 1st occurence.

For example: `?testCode_In=VGVzdENvZGVOb2RlOjQ=` will be parsed as: `{testCode_In: "VGVzdENvZGVOb2RlOjQ"}`.  This leads to confusion and inaccurate search terms.
@genomics-geek
Copy link
Contributor Author

@sindresorhus - Nice. I used your package like you suggested. This should take care of the GraphQL ids now 👍

@genomics-geek
Copy link
Contributor Author

@sindresorhus - is there anything else that is needed in order to merge?

@sindresorhus sindresorhus changed the title Parameters that contained = in value were being parsed inaccurately. Correctly handle query strings that contain = Mar 27, 2019
@sindresorhus sindresorhus merged commit 78e321c into sindresorhus:master Mar 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants