rbenv / ruby-build

A tool to download, compile, and install Ruby on Unix-like systems.
https://rbenv.org/man/ruby-build.1
MIT License
3.89k stars 785 forks source link

Failure to detect bz2 #2385

Closed konsolebox closed 6 months ago

konsolebox commented 6 months ago

https://github.com/rbenv/ruby-build/blob/0aefaa4e30428a895d74f603e04f7731fa7e026f/bin/ruby-build#L484

If package_url is like https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.0.tar.bz2#7aa247a19622a803bdd29fdb28108de9798abe841254fe8ea82c31d125c6ab26, that condition fails.

Perhaps change it to:

  if [ "$package_url" != "${package_url%.bz2*}" ]; then
mislav commented 6 months ago

Everything after # gets stripped from package_url a few lines above the line you've linked: https://github.com/rbenv/ruby-build/blob/0aefaa4e30428a895d74f603e04f7731fa7e026f/bin/ruby-build#L468-L470

konsolebox commented 6 months ago

Seems like this no longer works in Bash 5.3: ${package_url/\#}

konsolebox commented 6 months ago

I sent a bug report to bug-bash but maybe these issues can be avoided by using [[ $str != pattern ]]. There's no reason to make it POSIX compatible.

konsolebox commented 6 months ago

Bash devel branch has fixed the issue and I just tested ruby-build works again so I'm closing this now, thanks.

mislav commented 6 months ago

Thanks for reporting! I'm all for accepting a PR switching to [[ str != pattern ]] if bash 5.3 is already widely distributed and if it will take a while for the patch to roll out to package managers. But it's good to know this has been fixed.

Semi-related: something that I found out (in a different repo) the hard way is that newer versions of bash expand the ~ as a pathname in the expression ${str/pattern/~}, while bash 3.2 interprets it as a literal. For newer versions of bash, the solution is to backslash-escape the ~ sign, but in bash 3.2 the replacement would result in a literal \~. I couldn't find a way to make it work across bash versions, so I just rewrote the expression using different string replacement methods.

konsolebox commented 6 months ago

Thanks for reporting! I'm all for accepting a PR switching to [[ str != pattern ]] if bash 5.3 is already widely distributed and if it will take a while for the patch to roll out to package managers. But it's good to know this has been fixed.

Well Bash 5.3 is still in alpha stage so you don't have to worry. It's basically a use at your own risk version. In Gentoo for example, it doesn't even have a keyword. I OTOH prefer to install it (and sometimes the devel branch version) so I can find issues like this.