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


(Roger Pack) #1

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-


(Eric Wong) #2

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) }

···

Roger Pack <rogerdpack2@gmail.com> wrote:


(Roger Pack) #3

> this code:
>
> 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!

> 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) }

Thanks!

···

On Wed, Oct 24, 2018 at 3:37 PM Eric Wong <e@80x24.org> wrote:

Roger Pack <rogerdpack2@gmail.com> wrote: