gitlab/spec/bin
Sean McGivern 91e7b17cd1
Error on newlines in sidekiq-cluster arguments
When using Helm charts, which are YAML files, it's relatively easy to
accidentally include a newline in the Sidekiq arguments. This will
typically be a trailing newline, which shouldn't be a problem, except
that in our cloud-native deployment we launch Sidekiq using the command
given by `sidekiq-cluster --dryrun` (to avoid having the wrapper
process), so we effectively do:

    $(bin/sidekiq-cluster --dryrun $ARGS)

Ruby's `Shellwords.escape` quotes newlines as `'\n'`:
https://github.com/ruby/shellwords/blob/v0.1.0/lib/shellwords.rb#L161-L163

When those are parsed back in the arguments array we get `foo'\n'` for
an original argument of `foo\n`. Then, when we apply splitting, we get
`foo'` and `'` as two separate arguments.

The quoting here is quite complicated but the below demonstrates (in
Bash) what's happening:

    $ ruby -e 'p ARGV; p ARGV.first.split' "foo'"$'\n'"'"
    ["foo'\n'"]
    ["foo'", "'"]

If we did care about newlines in this argument array, the solution would
be more involved. But we don't, because they are never valid, so we can
just error when we encounter them.

Changelog: fixed
2021-09-01 12:08:06 +00:00
..
feature_flag_spec.rb
sidekiq_cluster_spec.rb Error on newlines in sidekiq-cluster arguments 2021-09-01 12:08:06 +00:00