Skip to content
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

Fix bug4 #396

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const queryString = require('./index');

// Example data that includes null and empty strings
const params = {
list: ['item', '', null, 'last']
};

// Options to reproduce the bug
const options = {
arrayFormat: 'comma',
skipNull: false,
skipEmptyString: false
};

// Stringify the parameters with the options
const result = queryString.stringify(params, options);

// Log the result to console
console.log(result); // Expected to incorrectly skip null and empty strings based on the bug
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import * as queryString from './base.js';

Check failure on line 1 in index.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Expected 1 empty line after import statement not followed by another import.

Check failure on line 1 in index.js

View workflow job for this annotation

GitHub Actions / Node.js 18

Expected 1 empty line after import statement not followed by another import.

export default queryString;

27 changes: 27 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,33 @@
t.deepEqual(queryString.stringify(queryString.parse(original, options), options), sortedOriginal);
});

test('circuit parse → stringify with array commas', t => {

Check failure on line 313 in test/parse.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Test title is used multiple times in the same file.

Check failure on line 313 in test/parse.js

View workflow job for this annotation

GitHub Actions / Node.js 18

Test title is used multiple times in the same file.
const original = 'c=,a,,&b=&a=';
const sortedOriginal = 'a=&b=&c=,a,,';
const expected = {
c: ['', 'a', '', ''],
b: '',
a: ''

Check failure on line 319 in test/parse.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Missing trailing comma.

Check failure on line 319 in test/parse.js

View workflow job for this annotation

GitHub Actions / Node.js 18

Missing trailing comma.
};
const options = {
arrayFormat: 'comma'

Check failure on line 322 in test/parse.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Missing trailing comma.

Check failure on line 322 in test/parse.js

View workflow job for this annotation

GitHub Actions / Node.js 18

Missing trailing comma.
};

t.deepEqual(queryString.parse(original, options), expected);

t.is(queryString.stringify(expected, options), sortedOriginal);
});

test('circuit original → parse → stringify with array commas → sorted original', t => {

Check failure on line 330 in test/parse.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Test title is used multiple times in the same file.

Check failure on line 330 in test/parse.js

View workflow job for this annotation

GitHub Actions / Node.js 18

Test title is used multiple times in the same file.
const original = 'c=,a,,&b=&a=';
const sortedOriginal = 'a=&b=&c=,a,,';
const options = {
arrayFormat: 'comma'

Check failure on line 334 in test/parse.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Missing trailing comma.

Check failure on line 334 in test/parse.js

View workflow job for this annotation

GitHub Actions / Node.js 18

Missing trailing comma.
};

t.deepEqual(queryString.stringify(queryString.parse(original, options), options), sortedOriginal);
});

test('decode keys and values', t => {
t.deepEqual(queryString.parse('st%C3%A5le=foo'), {ståle: 'foo'});
t.deepEqual(queryString.parse('foo=%7B%ab%%7C%de%%7D+%%7Bst%C3%A5le%7D%'), {foo: '{%ab%|%de%} %{ståle}%'});
Expand Down
12 changes: 12 additions & 0 deletions test/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@
}), 'bar=one,two&foo');
});

test('array stringify representation with array commas and null/empty values', t => {
const result = queryString.stringify({

Check failure on line 137 in test/stringify.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Expected indentation of 1 tab but found 4 spaces.

Check failure on line 137 in test/stringify.js

View workflow job for this annotation

GitHub Actions / Node.js 18

Expected indentation of 1 tab but found 4 spaces.
list: ['item', null, 'last', '']

Check failure on line 138 in test/stringify.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Expected indentation of 2 tabs but found 8 spaces.

Check failure on line 138 in test/stringify.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Missing trailing comma.

Check failure on line 138 in test/stringify.js

View workflow job for this annotation

GitHub Actions / Node.js 18

Expected indentation of 2 tabs but found 8 spaces.

Check failure on line 138 in test/stringify.js

View workflow job for this annotation

GitHub Actions / Node.js 18

Missing trailing comma.
}, {

Check failure on line 139 in test/stringify.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Expected indentation of 1 tab but found 4 spaces.

Check failure on line 139 in test/stringify.js

View workflow job for this annotation

GitHub Actions / Node.js 18

Expected indentation of 1 tab but found 4 spaces.
arrayFormat: 'comma',
skipNull: false,
skipEmptyString: false
});

t.is(result, 'list=item,,last,');
});

test('array stringify representation with array commas, null & empty string', t => {
t.is(queryString.stringify({
c: [null, 'a', '', null],
Expand Down