Project

General

Profile

Actions

Bug #18896

closed

Shellwords.escape(nil) returns "empty" string

Added by hspem (Per-Erik Martin) over 2 years ago. Updated over 2 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [powerpc-aix7.1.0]
[ruby-core:109142]

Description

Mistakenly calling Shellwords.escape with nil as parameter had this result:

irb(main):002:0> Shellwords.escape(nil)
=> "''"

This is not helpful and resulted a hard-to-find bug when a script proceeded to use an empty string where it shouldn't be possible. nil is not a string and escape should raise an exception instead.
Shellwords version:

# gem list shellwords

*** LOCAL GEMS ***

shellwords (default: 0.1.0)
# 

Updated by Dan0042 (Daniel DeLorme) over 2 years ago

Shellwords.escape just converts the argument to a string before shell-escaping it, so in this context nil is equivalent to ""

Shellwords.escape("")         #=> "''"
Shellwords.escape(42)         #=> "42"
Shellwords.escape(Object.new) #=> "\\#\\<Object:0x00007f01ae28c3a8\\>"

At this point, changing the API in such a backward-incompatible way would cause more problems than benefit.

Actions #2

Updated by jeremyevans0 (Jeremy Evans) over 2 years ago

  • Status changed from Open to Rejected
Actions

Also available in: Atom PDF

Like0
Like0Like0