Re: should I be able to write to filenames with a pipe in them?

Eric Wong <[email protected]>
Newsgroups gmane.comp.lang.ruby.general
Message-ID <20181024213651.rquc4ngrjif4iy2r@dcvr>
Roger Pack <[email protected]> wrote:
> this code:
> 
> a = "|AB|"
> File.write(a, a)

That spawns a shell in older Rubies and was a security problem
last year or so.

> 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?

Using File.open instead works for all versions of Ruby:

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

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.