-
Notifications
You must be signed in to change notification settings - Fork 126
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
⚡ use qs_dart for query string encoding #592
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #592 +/- ##
===========================================
- Coverage 94.19% 93.52% -0.68%
===========================================
Files 11 12 +1
Lines 482 463 -19
===========================================
- Hits 454 433 -21
- Misses 28 30 +2 ☔ View full report in Codecov by Sentry. |
I propose this goes into v8.0.0 since it slightly changes the way CC / @JEuler @Guldem @diegotori |
Makes sense. Introduce all changes at once 😉 LGTM! Also want someone to have a look at qs_dart? |
Please :) I converted all the tests of qs, however, porting the JavaScript code was quite the ordeal since it's not typed and written in such a legacy way that made me cry a few times 🙈 |
Have looked globally at the code of |
@techouse I still need to add the encoding tests that evaluate Strapi query map encoding into this library's tests. Also, please consider adding an option for indexed bracketed arrays, unless |
I'm working on deprecating the current tags (while still keeping them) and adding a new ones which will give the user an option to encode with any of these:
|
@techouse I think we should also target this for Otherwise, the changes related to the interceptors might get in the way if we have to upgrade to Not to mention, it gives you time to deprecate |
That's fine! This is needed, the interceptors not necessarily 😄 |
I've added a new annotation /// List format to use when encoding lists
///
/// - [ListFormat.repeat] (default) hxxp://path/to/script?foo=123&foo=456&foo=789
/// - [ListFormat.brackets] hxxp://path/to/script?foo[]=123&foo[]=456&foo[]=789
/// - [ListFormat.indices] hxxp://path/to/script?foo[0]=123&foo[1]=456&foo[2]=789
/// - [ListFormat.comma] hxxp://path/to/script?foo=123,456,789
final ListFormat? listFormat; and have deprecated /// Use brackets [ ] to when encoding
///
/// - lists
/// hxxp://path/to/script?foo[]=123&foo[]=456&foo[]=789
///
/// - maps
/// hxxp://path/to/script?user[name]=john&user[surname]=doe&user[age]=21
@Deprecated('Use listFormat instead')
final bool? useBrackets; In line with the above I have also modified String mapToQuery(
Map<String, dynamic> map, {
ListFormat? listFormat,
@Deprecated('Use listFormat instead') bool? useBrackets,
bool? includeNullQueryVars,
}) {
listFormat ??= useBrackets == true ? ListFormat.brackets : ListFormat.repeat;
return QS.encode(
map,
EncodeOptions(
listFormat: listFormat,
allowDots: listFormat == ListFormat.repeat,
encodeDotInKeys: listFormat == ListFormat.repeat,
encodeValuesOnly: listFormat == ListFormat.repeat,
skipNulls: includeNullQueryVars != true,
strictNullHandling: false,
serializeDate: (DateTime date) => date.toUtc().toIso8601String(),
),
);
} and added a tonne of tests 🤪 CC / @JEuler @Guldem @diegotori |
@diegotori could you please test this PR in your problematic project/app and report back any findings? dependency_overrides:
chopper:
git:
url: https://github.com/lejard-h/chopper.git
ref: fix/issue-584-qs
path: chopper
chopper_generator:
git:
url: https://github.com/lejard-h/chopper.git
ref: fix/issue-584-qs
path: chopper_generator |
I dunno if I have the capacity to do that currently. However, once you release it and we start the process of migrating to using this new version, if there are any issues, we'll be sure to raise them. So far, the tests that were added to both this library and Since |
I tried my best to port everything that could be ported, however, I could not make it a 1:1 port because of some core differences between JavaScript and Dart, i.e. Object prototypes, sparse arrays, etc. |
No worries. So far, it's spitting out Strapi-compatible query strings, and that's what really matters for us. That way, we won't have to do backend hackery to get around the previous limitations. Standby for another set of tests that you'll need to add so that it covers ones that I found. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
EDIT: Fixed |
* 🔖 release v7.4.0 # chopper ## 7.4.0 - #592 # chopper_generator ## 7.4.0 - #592 --------- Signed-off-by: dependabot[bot] <[email protected]>
@diegotori noticed that a
Map<String, dynamic>
like thisdid not get encoded properly to
but became this
This PR fixes this by using an external library qs_dart which is a Dart port of qs that I've been painstakingly working on over the past couple of weeks. 🤓
This now means that the output of Chopper, while still backwards compatible, is now qs compatible.
The only caveat is
null
and emptyString
handling in query strings, which is a bit different in qs and therefore also qs_dart.Please check the various test case changes to see these
null
and emptyString
differences.Addresses #584
Supersedes #591
CC / @JEuler @Guldem @diegotori