Skip to content

Bug Fix on Windows changing /USER~1/ to /User Name/ #542

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

Closed
wants to merge 2 commits into from

Conversation

garrrth
Copy link

@garrrth garrrth commented Jan 27, 2017

🌈

This is to fix a bug that I (and others, see rspec#1555, rspec#1577, rspec#1747 and rails#27129) have experienced when running rails generate rspec:install on a windows machine.

Ruby creates a tmpdir with /USER~1/ and then thor uses another method, files(lookup), that converts it to /User Name/ and tries to compare the two and gsub it out when it assigns it to file_destination. My fix, though a little hacky (I'm new to Ruby and don't really know of a better way in all honesty) works and shouldn't create problems elsewhere as far as I can see.

@piotrmurach
Copy link

Hey, great that you have looked into this. I'm a bit concerned about the fix because the regex assumes ~1 to proceed username but what about legitimate file paths that contain such characters? Also I would encourage you to write a test that demonstrates this problem/fix.

@garrrth
Copy link
Author

garrrth commented Feb 13, 2017

Hey Piotr, thanks for your feedback. I have a different approach to this now - replacing the file path that is created by Dir.glob with it's original stored in lookup. I also have it only performing the replacement when it sees a windows environment variable for username (which I can imagine is the only use case for this). I'll write a test before pushing it up, but that will be after work 😞 !

@garrrth
Copy link
Author

garrrth commented Feb 13, 2017

I'm questioning myself right now as to whether this is the right fix!! It is essentially a work around rather than a fix. For example, this issue could be remedied in this part on thor, or on rspec which is creating the tmpdir file path before it is sent to thor.

It is essentially Dir.glob(lookup, File::FNM_DOTMATCH) that is making the change from USER~1 to User Name, so is there another method that could replace this that doesn't make that change??

@garrrth
Copy link
Author

garrrth commented Feb 13, 2017

Ok, digging more unearths that this is something that has arisen since Ruby 2.3. See Ruby Issue #10819 referenced from Puppet pull-request #5156.

Also struggling to figure out what exactly I need to test for with this (I'm new to writing tests and all that!).

@TraGicCode
Copy link

Any uodate in this

@mathieurousseau
Copy link

Any update on this? still can't run rspec:install on windows machine

@MarcoDeJesus
Copy link

Followed the work around and updated the file by my own and I'm able to continue working. Thanks @garrrth

@ghost ghost mentioned this pull request Apr 28, 2019
rafaelfranca added a commit that referenced this pull request Sep 12, 2019
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.

6 participants