Skip to content

Tokenize OPAMFETCH value properly, not splitting by whitespaces #5490

@scjung

Description

@scjung
# opam config report
# opam-version         2.2.0~alpha~dev (7f4558d65bbfbf4524e413ab7d06d8ac5f4484d3)
# self-upgrade         no
# system               arch=x86_64 os=macos os-distribution=homebrew os-version=13.2.1
# solver               builtin-mccs+glpk
# install-criteria     -removed,-count[avoid-version,changed],-count[version-lag,request],-count[version-lag,changed],-count[missing-depexts,changed],-changed
# upgrade-criteria     -removed,-count[avoid-version,changed],-count[version-lag,solution],-count[missing-depexts,changed],-new
# jobs                 7
# repositories         1 (http), 1 (version-controlled) (default repo at 5811dd22)
# pinned               0
# current-switch       5.0
# invariant            ocaml-base-compiler >= 5.0 & ocaml-base-compiler < 5.1
# compiler-packages    ocaml-base-compiler.5.0.0, ocaml-options-vanilla.1
# ocaml:native         true
# ocaml:native-tools   true
# ocaml:native-dynlink true
# ocaml:stubsdir       /Users/mukka/.opam/5.0/lib/ocaml/stublibs:/Users/mukka/.opam/5.0/lib/ocaml
# ocaml:preinstalled   false
# ocaml:compiler       5.0.0

Because OPAM splits OPAMFETCH value by spaces, the use-case below does not work as expected.

# The package is in private Github repo, so we supply access token in Authorize header.
$ OPAMFETCH='wget --header "Authorization: token >>>redacted<<<" %{url}% -O %{out}%' opam install coreutil

... snip ...
+ /usr/bin/wget "--header" "\"Authorization:" "token" ">>>redacted<<<\"" "-O" "/home/scjung/.opam/4.12.1/.opam-switch/sources/coreutil.1.10/v1.10.tar.gz.part" "%{url}"
- --2023-03-24 10:31:27--  http://token/
- Resolving token (token)... failed: Name or service not known.
- wget: unable to resolve host address ‘token’

As you may see in the log, "Authorization: token ..." argument is parsed into seperate words.

OPAM should tokenize OPAMFETCH value in the way shell tokenizes[1, 2], so that a quoted argument is parsed as a single string rather than separate words.

[1] https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
[2] https://github.com/dbuenzli/bos/blob/master/src/bos_cmd.ml#L46-L112

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions