Forum: Ruby-core [ruby-trunk - Bug #8034][Open] File.expand_path('something', '~') do not include home path

Posted by rap-kasta (Pavel Manylov) (Guest)
on 2013-03-06 14:44
(Received via mailing list)
Issue #8034 has been reported by rap-kasta (Pavel Manylov).

----------------------------------------
Bug #8034: File.expand_path('something', '~') do not include home path
https://bugs.ruby-lang.org/issues/8034

Author: rap-kasta (Pavel Manylov)
Status: Open
Priority: Normal
Assignee: cruby-windows
Category: platform/windows
Target version:
ruby -v: 1.9.3p362


=begin
Next code works correctly only on ruby <= 1.9.3p362.
Tested on Windows XP, Windows 2008 with ruby 1.9.3p194 (works properly), 
ruby 1.9.3p362 (bug), ruby 2.0.0p0 (bug).

(({File.expand_path('something', '~') #=> 
"C:/path/to/current/dir/~/something"}))

However, next code works as it should in all tested rubies:

(({File.expand_path '~' # => "C:/Documents and Settings/Jack"
Dir.home # => "C:/Documents and Settings/Jack"}))
=end
Posted by Luis Lavena (luislavena)
on 2013-03-06 15:34
(Received via mailing list)
Issue #8034 has been updated by luislavena (Luis Lavena).

Assignee changed from cruby-windows to luislavena (Luis Lavena)


----------------------------------------
Bug #8034: File.expand_path('something', '~') do not include home path
https://bugs.ruby-lang.org/issues/8034#change-37331

Author: rap-kasta (Pavel Manylov)
Status: Open
Priority: Normal
Assignee: luislavena (Luis Lavena)
Category: platform/windows
Target version:
ruby -v: 1.9.3p362


=begin
Next code works correctly only on ruby <= 1.9.3p362.
Tested on Windows XP, Windows 2008 with ruby 1.9.3p194 (works properly), 
ruby 1.9.3p362 (bug), ruby 2.0.0p0 (bug).

(({File.expand_path('something', '~') #=> 
"C:/path/to/current/dir/~/something"}))

However, next code works as it should in all tested rubies:

(({File.expand_path '~' # => "C:/Documents and Settings/Jack"
Dir.home # => "C:/Documents and Settings/Jack"}))
=end
Posted by Luis Lavena (luislavena)
on 2013-03-10 15:45
(Received via mailing list)
Issue #8034 has been updated by luislavena (Luis Lavena).


Hello,

This has been fixed in trunk and backports for both 2.0.0 and 1.9.3 have 
been requested.

Thank you for your report.
----------------------------------------
Bug #8034: File.expand_path('something', '~') do not include home path
https://bugs.ruby-lang.org/issues/8034#change-37456

Author: rap-kasta (Pavel Manylov)
Status: Closed
Priority: Normal
Assignee: luislavena (Luis Lavena)
Category: platform/windows
Target version:
ruby -v: 1.9.3p362


=begin
Next code works correctly only on ruby <= 1.9.3p362.
Tested on Windows XP, Windows 2008 with ruby 1.9.3p194 (works properly), 
ruby 1.9.3p362 (bug), ruby 2.0.0p0 (bug).

(({File.expand_path('something', '~') #=> 
"C:/path/to/current/dir/~/something"}))

However, next code works as it should in all tested rubies:

(({File.expand_path '~' # => "C:/Documents and Settings/Jack"
Dir.home # => "C:/Documents and Settings/Jack"}))
=end
Posted by Nobuyoshi Nakada (nobu)
on 2013-03-10 16:33
(Received via mailing list)
Issue #8034 has been updated by nobu (Nobuyoshi Nakada).


Why is File.expand_path('something', '~whoever') ignored?

----------------------------------------
Bug #8034: File.expand_path('something', '~') do not include home path
https://bugs.ruby-lang.org/issues/8034#change-37459

Author: rap-kasta (Pavel Manylov)
Status: Closed
Priority: Normal
Assignee: luislavena (Luis Lavena)
Category: platform/windows
Target version:
ruby -v: 1.9.3p362


=begin
Next code works correctly only on ruby <= 1.9.3p362.
Tested on Windows XP, Windows 2008 with ruby 1.9.3p194 (works properly), 
ruby 1.9.3p362 (bug), ruby 2.0.0p0 (bug).

(({File.expand_path('something', '~') #=> 
"C:/path/to/current/dir/~/something"}))

However, next code works as it should in all tested rubies:

(({File.expand_path '~' # => "C:/Documents and Settings/Jack"
Dir.home # => "C:/Documents and Settings/Jack"}))
=end
Posted by Luis Lavena (luislavena)
on 2013-03-10 17:03
(Received via mailing list)
Issue #8034 has been updated by luislavena (Luis Lavena).


=begin
nobu (Nobuyoshi Nakada) wrote:
> =begin
> Why is (({File.expand_path('something', '~whoever')})) ignored?

There is no test for that, I didn't see a test that verifies that 
behavior so I didn't add code for it.

Also, (({~user})) doesn't work as you expect on Windows.
> =end

=end

----------------------------------------
Bug #8034: File.expand_path('something', '~') do not include home path
https://bugs.ruby-lang.org/issues/8034#change-37465

Author: rap-kasta (Pavel Manylov)
Status: Closed
Priority: Normal
Assignee: luislavena (Luis Lavena)
Category: platform/windows
Target version:
ruby -v: 1.9.3p362


=begin
Next code works correctly only on ruby <= 1.9.3p362.
Tested on Windows XP, Windows 2008 with ruby 1.9.3p194 (works properly), 
ruby 1.9.3p362 (bug), ruby 2.0.0p0 (bug).

(({File.expand_path('something', '~') #=> 
"C:/path/to/current/dir/~/something"}))

However, next code works as it should in all tested rubies:

(({File.expand_path '~' # => "C:/Documents and Settings/Jack"
Dir.home # => "C:/Documents and Settings/Jack"}))
=end
Posted by Luis Lavena (luislavena)
on 2013-03-10 17:11
(Received via mailing list)
Issue #8034 has been updated by luislavena (Luis Lavena).

Status changed from Closed to Assigned
% Done changed from 100 to 50

=begin
Nobu,

I'll add test for (({File.expand_path('something', '~whoever')})) and 
add support for it in ((|dir_string|)).

=end

----------------------------------------
Bug #8034: File.expand_path('something', '~') do not include home path
https://bugs.ruby-lang.org/issues/8034#change-37469

Author: rap-kasta (Pavel Manylov)
Status: Assigned
Priority: Normal
Assignee: luislavena (Luis Lavena)
Category: platform/windows
Target version:
ruby -v: 1.9.3p362


=begin
Next code works correctly only on ruby <= 1.9.3p362.
Tested on Windows XP, Windows 2008 with ruby 1.9.3p194 (works properly), 
ruby 1.9.3p362 (bug), ruby 2.0.0p0 (bug).

(({File.expand_path('something', '~') #=> 
"C:/path/to/current/dir/~/something"}))

However, next code works as it should in all tested rubies:

(({File.expand_path '~' # => "C:/Documents and Settings/Jack"
Dir.home # => "C:/Documents and Settings/Jack"}))
=end
Posted by Luis Lavena (luislavena)
on 2013-03-10 20:42
(Received via mailing list)
Issue #8034 has been updated by luislavena (Luis Lavena).

Assignee changed from luislavena (Luis Lavena) to h.shirosaki (Hiroshi 
Shirosaki)

Following patch solves the issue:

https://gist.github.com/luislavena/5130078

However there is lot of duplication between wpath and wdir checks, which 
is crying for a refactoring.

Shirosaki-san, what do you think?
----------------------------------------
Bug #8034: File.expand_path('something', '~') do not include home path
https://bugs.ruby-lang.org/issues/8034#change-37474

Author: rap-kasta (Pavel Manylov)
Status: Assigned
Priority: Normal
Assignee: h.shirosaki (Hiroshi Shirosaki)
Category: platform/windows
Target version:
ruby -v: 1.9.3p362


=begin
Next code works correctly only on ruby <= 1.9.3p362.
Tested on Windows XP, Windows 2008 with ruby 1.9.3p194 (works properly), 
ruby 1.9.3p362 (bug), ruby 2.0.0p0 (bug).

(({File.expand_path('something', '~') #=> 
"C:/path/to/current/dir/~/something"}))

However, next code works as it should in all tested rubies:

(({File.expand_path '~' # => "C:/Documents and Settings/Jack"
Dir.home # => "C:/Documents and Settings/Jack"}))
=end
Posted by h.shirosaki (Hiroshi Shirosaki) (Guest)
on 2013-03-10 22:03
(Received via mailing list)
Issue #8034 has been updated by h.shirosaki (Hiroshi Shirosaki).

Assignee changed from h.shirosaki (Hiroshi Shirosaki) to luislavena 
(Luis Lavena)

Luis, thank you for your work.
`xfree(wpath);` would be needed before rb_raise(rb_eArgError, "can't 
find user %s"...
Indeed refactoring is better if possible.
----------------------------------------
Bug #8034: File.expand_path('something', '~') do not include home path
https://bugs.ruby-lang.org/issues/8034#change-37475

Author: rap-kasta (Pavel Manylov)
Status: Assigned
Priority: Normal
Assignee: luislavena (Luis Lavena)
Category: platform/windows
Target version:
ruby -v: 1.9.3p362


=begin
Next code works correctly only on ruby <= 1.9.3p362.
Tested on Windows XP, Windows 2008 with ruby 1.9.3p194 (works properly), 
ruby 1.9.3p362 (bug), ruby 2.0.0p0 (bug).

(({File.expand_path('something', '~') #=> 
"C:/path/to/current/dir/~/something"}))

However, next code works as it should in all tested rubies:

(({File.expand_path '~' # => "C:/Documents and Settings/Jack"
Dir.home # => "C:/Documents and Settings/Jack"}))
=end
Posted by Luis Lavena (luislavena)
on 2013-03-13 02:24
(Received via mailing list)
Issue #8034 has been updated by luislavena (Luis Lavena).

Assignee changed from luislavena (Luis Lavena) to h.shirosaki (Hiroshi 
Shirosaki)
% Done changed from 50 to 70

=begin
Shirosaki-san,

I've refactored the code, would you mind take a look?

https://gist.github.com/luislavena/5148562

After applying the patch, it fixes the original issue, however now 
nobu-san added another test:

 assert_nothing_raised(ArgumentError) { File.expand_path("/", 
UnknownUserHome) }

Which requires more conditions if (({fname})) is '/' and set 
(({ignore_dir})) accordingly, but I'm confused about the scenario.

I'm not sure if that scenario is portable and correct since 1.8.7 and 
1.9.2 return ArgumentError:

 C:\Users\Luis>ruby -ve "p File.expand_path('/', '~foo')"
 ruby 1.8.7 (2012-10-12 patchlevel 371) [i386-mingw32]
 -e:1:in `expand_path': can't find user ~foo (ArgumentError)
         from -e:1

 C:\Users\Luis>ruby -ve "p File.expand_path('/', '~foo')"
 ruby 1.9.2p290 (2011-07-09) [i386-mingw32]
 -e:1:in `expand_path': can't find user foo (ArgumentError)
         from -e:1:in `<main>'

Thoughts?

=end
----------------------------------------
Bug #8034: File.expand_path('something', '~') do not include home path
https://bugs.ruby-lang.org/issues/8034#change-37550

Author: rap-kasta (Pavel Manylov)
Status: Assigned
Priority: Normal
Assignee: h.shirosaki (Hiroshi Shirosaki)
Category: platform/windows
Target version:
ruby -v: 1.9.3p362


=begin
Next code works correctly only on ruby <= 1.9.3p362.
Tested on Windows XP, Windows 2008 with ruby 1.9.3p194 (works properly), 
ruby 1.9.3p362 (bug), ruby 2.0.0p0 (bug).

(({File.expand_path('something', '~') #=> 
"C:/path/to/current/dir/~/something"}))

However, next code works as it should in all tested rubies:

(({File.expand_path '~' # => "C:/Documents and Settings/Jack"
Dir.home # => "C:/Documents and Settings/Jack"}))
=end
Posted by Nobuyoshi Nakada (nobu)
on 2013-03-13 04:56
(Received via mailing list)
Issue #8034 has been updated by nobu (Nobuyoshi Nakada).


luislavena (Luis Lavena) wrote:
> After applying the patch, it fixes the original issue, however now nobu-san 
added another test:
>
>  assert_nothing_raised(ArgumentError) { File.expand_path("/", UnknownUserHome) }
>
> Which requires more conditions if (({fname})) is '/' and set (({ignore_dir})) 
accordingly, but I'm confused about the scenario.

Sorry, fixed the test, it shoud raise an exception on Windows, but the
latest test should not.

----------------------------------------
Bug #8034: File.expand_path('something', '~') do not include home path
https://bugs.ruby-lang.org/issues/8034#change-37560

Author: rap-kasta (Pavel Manylov)
Status: Assigned
Priority: Normal
Assignee: h.shirosaki (Hiroshi Shirosaki)
Category: platform/windows
Target version:
ruby -v: 1.9.3p362


=begin
Next code works correctly only on ruby <= 1.9.3p362.
Tested on Windows XP, Windows 2008 with ruby 1.9.3p194 (works properly), 
ruby 1.9.3p362 (bug), ruby 2.0.0p0 (bug).

(({File.expand_path('something', '~') #=> 
"C:/path/to/current/dir/~/something"}))

However, next code works as it should in all tested rubies:

(({File.expand_path '~' # => "C:/Documents and Settings/Jack"
Dir.home # => "C:/Documents and Settings/Jack"}))
=end
Posted by h.shirosaki (Hiroshi Shirosaki) (Guest)
on 2013-03-13 14:47
(Received via mailing list)
Issue #8034 has been updated by h.shirosaki (Hiroshi Shirosaki).

Assignee changed from h.shirosaki (Hiroshi Shirosaki) to luislavena 
(Luis Lavena)

luislavena (Luis Lavena) wrote:
> I've refactored the code, would you mind take a look?
>
> https://gist.github.com/luislavena/5148562
>

Coding style is inconsistent at if/else. Otherwise, looks good to me. 
Thank you.


diff --git a/win32/file.c b/win32/file.c
index 53cf085..350f8da 100644
--- a/win32/file.c
+++ b/win32/file.c
@@ -333,14 +333,12 @@ get_user_from_path(wchar_t **wpath, int offset, 
UINT cp, UINT path_cp, rb_encodi
     convert_wchar_to_mb(wuser, &user, &size, cp);

     /* convert to VALUE and set the path encoding */
-    if (path_cp == INVALID_CODE_PAGE)
-    {
+    if (path_cp == INVALID_CODE_PAGE) {
   tmp = rb_enc_str_new(user, size, rb_utf8_encoding());
   result = rb_str_encode(tmp, rb_enc_from_encoding(path_encoding), 0, 
Qnil);
   rb_str_resize(tmp, 0);
     }
-    else
-    {
+    else {
   result = rb_enc_str_new(user, size, path_encoding);
     }


----------------------------------------
Bug #8034: File.expand_path('something', '~') do not include home path
https://bugs.ruby-lang.org/issues/8034#change-37571

Author: rap-kasta (Pavel Manylov)
Status: Assigned
Priority: Normal
Assignee: luislavena (Luis Lavena)
Category: platform/windows
Target version:
ruby -v: 1.9.3p362


=begin
Next code works correctly only on ruby <= 1.9.3p362.
Tested on Windows XP, Windows 2008 with ruby 1.9.3p194 (works properly), 
ruby 1.9.3p362 (bug), ruby 2.0.0p0 (bug).

(({File.expand_path('something', '~') #=> 
"C:/path/to/current/dir/~/something"}))

However, next code works as it should in all tested rubies:

(({File.expand_path '~' # => "C:/Documents and Settings/Jack"
Dir.home # => "C:/Documents and Settings/Jack"}))
=end
Posted by Luis Lavena (luislavena)
on 2013-03-14 17:08
(Received via mailing list)
Issue #8034 has been updated by luislavena (Luis Lavena).


h.shirosaki (Hiroshi Shirosaki) wrote:
> Luis, thank you for your work.
> `xfree(wpath);` would be needed before rb_raise(rb_eArgError, "can't find user 
%s"...
> Indeed refactoring is better if possible.

Hiroshi,

I've pushed the refactored code as r39751 and corrected the style issue 
you mentioned. Thank you.

I noticed getting the user home directory when detected "~" in either 
wpath or wdir can be refactored too.

But that is for another ticket :)

Thank you.
----------------------------------------
Bug #8034: File.expand_path('something', '~') do not include home path
https://bugs.ruby-lang.org/issues/8034#change-37601

Author: rap-kasta (Pavel Manylov)
Status: Closed
Priority: Normal
Assignee: luislavena (Luis Lavena)
Category: platform/windows
Target version:
ruby -v: 1.9.3p362


=begin
Next code works correctly only on ruby <= 1.9.3p362.
Tested on Windows XP, Windows 2008 with ruby 1.9.3p194 (works properly), 
ruby 1.9.3p362 (bug), ruby 2.0.0p0 (bug).

(({File.expand_path('something', '~') #=> 
"C:/path/to/current/dir/~/something"}))

However, next code works as it should in all tested rubies:

(({File.expand_path '~' # => "C:/Documents and Settings/Jack"
Dir.home # => "C:/Documents and Settings/Jack"}))
=end
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.