Discussion:
should I be able to write to filenames with a pipe in them?
Roger Pack
2018-10-24 21:21:35 UTC
Permalink
this code:

a = "|AB|"
File.write(a, a)

fails:

$ ruby -v bad.rb
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
sh: -c: line 1: syntax error: unexpected end of file

Filenames with pipes in them are valid in linux. Is there something
I'm missing here or is this a bug do you think?

-Roger Pack-

Unsubscribe: <mailto:ruby-talk-***@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Eric Wong
2018-10-24 21:36:51 UTC
Permalink
Post by Roger Pack
a = "|AB|"
File.write(a, a)
That spawns a shell in older Rubies and was a security problem
last year or so.
Post by Roger Pack
$ ruby -v bad.rb
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
sh: -c: line 1: syntax error: unexpected end of file
Filenames with pipes in them are valid in linux. Is there something
I'm missing here or is this a bug do you think?
Using File.open instead works for all versions of Ruby:

a = "|AB|"
File.open(a, 'w') { |fp| fp.write(a) }

Unsubscribe: <mailto:ruby-talk-***@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Roger Pack
2018-10-26 19:55:25 UTC
Permalink
Post by Eric Wong
Post by Roger Pack
a = "|AB|"
File.write(a, a)
That spawns a shell in older Rubies and was a security problem
last year or so.
Ahh it was like a magic filename of some kind. Gotcha.
Thanks!
Post by Eric Wong
Post by Roger Pack
Filenames with pipes in them are valid in linux. Is there something
I'm missing here or is this a bug do you think?
a = "|AB|"
File.open(a, 'w') { |fp| fp.write(a) }
Thanks!

Unsubscribe: <mailto:ruby-talk-***@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Loading...