Skip to content

Track: mvdan.cc/sh array slicing bug workaround #57

Description

@kolkov

Summary

We have a workaround in internal/metadata/evaluator.go for a bug in mvdan.cc/sh where array slicing inside double quotes returns the full array instead of the slice.

The Bug

# Bash (correct)
$ bash -c 'a=(1 2 3 4 5); echo "${a[@]:2:2}"'
3 4

# mvdan.cc/sh (wrong)
$ gosh -c 'a=(1 2 3 4 5); echo "${a[@]:2:2}"'
1 2 3 4 5

Without quotes it works correctly:

$ gosh -c 'a=(1 2 3 4 5); echo ${a[@]:2:2}'
3 4

Upstream

Workaround

internal/metadata/evaluator.go — The ver_cut function uses indexed variables (comp_0, comp_1, ...) instead of array slicing to avoid the bug.

Action Items

  • Monitor upstream issue status
  • When mvdan.cc/sh releases fix, update dependency
  • Remove workaround and use standard array slicing
  • Close this issue

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions