Issue #13223 has been updated by Aaron Patterson.
@nobu I went by what the documentation says:
~~~
/*
* call-seq:
* File.join(string, ...) -> string
*
* Returns a new string formed by joining the strings using
* <code>File::SEPARATOR</code>.
*
* File.join("usr", "mail", "gumby") #=> "usr/mail/gumby"
*
*/
~~~
The current implementation doesn't seem to care what the value of `File::SEPARATOR` is, so I think it's a bug. Also JRuby has this behavior:
~~~
$ jruby -v -e'File.const_set(:SEPARATOR, "$"); p File.join("a","b")'
jruby 9.1.6.0 (2.3.1) 2016-11-09 0150a76 Java HotSpot(TM) 64-Bit Server VM 25.77-b03 on 1.8.0_77-b03 +jit [darwin-x86_64]
-e:1: warning: already initialized constant SEPARATOR
"a$b"
~~~
----------------------------------------
Bug #13223: `File.join` will segv if File::SEPARATOR and File::Separator are set.
https://bugs.ruby-lang.org/issues/13223#change-63013
* Author: Aaron Patterson
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.5.0dev (2017-02-17 trunk 57648) [x86_64-darwin16]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
The program below will crash with a segv:
~~~ruby
File.const_set :Separator, "hello"
File.const_set :SEPARATOR, "hello"
GC.start
File.join "hello", "world"
~~~
This is because the separator object is referenced from a global variable and setting the constants allows the object to be GC'd and the global will go bad.
I've attached a patch that contains a test to demonstrate the problem along with a fix.
---Files--------------------------------
0001-Fix-segv-in-File.join-when-SEPARATOR-and-Separator-a.patch (3.04 KB)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>