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

[Fixes #180] Allow for root-level arrays to be querystring-ed in Modem.prototype.buildQuerystring #181

Merged
merged 5 commits into from
Jan 13, 2025
Merged
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
10 changes: 4 additions & 6 deletions lib/modem.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,13 +529,11 @@ Modem.prototype.followProgress = function (streama, onFinished, onProgress) {
Modem.prototype.buildQuerystring = function (opts) {
var clone = {};

// serialize map and array values as JSON strings, else querystring truncates.
// 't' and 'extrahosts' can be arrays but need special treatment so that they're
// passed as multiple qs parameters instead of JSON values.
Object.keys(opts).map(function (key, i) {
if (opts[key]
&& typeof opts[key] === 'object'
&& !['t', 'extrahosts'].includes(key)
if (
opts[key] &&
typeof opts[key] === 'object' &&
!Array.isArray(opts[key])
Copy link

Choose a reason for hiding this comment

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

@Clovel @apocas This change is quite aggressive, it goes for using query serialization for only t and extrahosts to using it for any Array option.

This doesn't seem to be universally true. At least I can see this breaks the cachefrom on Image.build that expects a JSON serialized array and otherwise it errors with

(HTTP code 400) unexpected - error reading cache-from: invalid character 'a' looking for beginning of value

I confirmed the issue does not happen with docker-modem v5.0.3, prior to this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would seem that the serialization needs to be more standard indeed. Not all routes behave the same (or at least I haven't found a common denominator).

It does fix the usage of ENV variables and other parameters of the /images/create route though, which was my issue.

Also unit tests pass, so a case seems to be missing for your issue.

Copy link

Choose a reason for hiding this comment

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

In the Moby code, t and extrahosts are read using Request.Form (see lines 55-56), while cachefrom uses Request.FormValue (see line 143). I don't know enough about Go to understand why the data is interpreted differently, but that could give us a clue.

Copy link

Choose a reason for hiding this comment

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

Yeah, the docker API is not very consistent with how it accepts array parameters.

  • cachefrom in ImageBuild expects a stringified "JSON array of images"
  • changes in ImageCreate expects an array of strings.

I'll open up an issue and possibly a PR

) {
clone[key] = JSON.stringify(opts[key]);
} else {
Expand Down
Loading