Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4116. Make dirname aware of the file system's path separator #4175

Closed
wants to merge 1 commit into from

Conversation

jsyeo
Copy link
Contributor

@jsyeo jsyeo commented Sep 23, 2016

I removed the line that normalizes the path to be separated by / and instead make it aware of the file system's separator.

@enebo
Copy link
Member

enebo commented Sep 23, 2016

@jsyeo This change will break windows compatibility but fix non-windows. On windows both / and \ will work in dirname (it is how MRI works anyways) whereas on all other platforms it treats \ as literalizing character. So I think maybe the fix might be to just put an if check on the original gsub to convert \ to / if only on windows.

@headius
Copy link
Member

headius commented Sep 23, 2016

@enebo I don't think this will break anything on Windows, since the backslashes are not going to be interpreted as escapes (they're literally in the string, not syntactically inside a literal string).

However it may break other things by returning backslashes in the resulting path. I think MRI normalizes everything to / internally, right? Does any core MRI File method return a backslashy path on Windows?

@jsyeo Thank you for the PR! Are you on Windows or a UNIX system?

@headius headius added this to the JRuby 9.1.6.0 milestone Sep 23, 2016
@jsyeo
Copy link
Contributor Author

jsyeo commented Sep 24, 2016

@jsyeo Thank you for the PR! Are you on Windows or a UNIX system?

I'm on an unix system. Hmm, I kinda assumed that it would be the inverse on a windows system. Let me spin up a windows vm and install mri to try out its File.dirname behavior.

@danini-the-panini
Copy link
Contributor

The MRI implementation does pretty much what it says in the documentation:

Returns all components of the filename given in file_name except the last one. The filename can be formed using both File::SEPARATOR and File::ALT_SEPARATOR as the separator when File::ALT_SEPARATOR is not nil.

File::SEPARATOR is always /. However, File::ALT_SEPARATOR is nil on Unix and \ on Windows. The net result is that on Windows, either separator can be used interchangeably, but on Unix, only / is recognised.

I started working on a solution to #4116 for a while now, but I couldn't test on windows since I had some issues with Maven on my VM. Now that they've been fixed I've managed to put together what I believe to be a solid fix for both Unix and Windows environments. You can examine my proposed changes here: #4177.

@enebo
Copy link
Member

enebo commented Sep 24, 2016

@jellymann thanks for checking on the details of this. You gave a clearer explanation than me of the issue. I see there is a new PR to fix this so we will likely have a golden PR now :)

@headius I only pointed this out since I tested it on windows and it returns using either \ and / as a delimeter (which fits @jellymann desciption as to why). I think we can maybe even make a nice test for this in spec which adds ALT_SEPARATOR so we can test windows behavior on non-windows ci runs too.

Duplcating as there is a new PR now.

@enebo enebo closed this Sep 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants