Method: Rex::FileUtils.normalize_win_path
- Defined in:
- lib/rex/file.rb
.normalize_win_path(*strs) ⇒ Object
This method joins the paths together in Windows format. All reserved characters will be filtered out, including:
" * : < > ? \ / |
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rex/file.rb', line 31 def self.normalize_win_path(*strs) # Convert to the same format so the parsing is easier s = strs * '\\' # Filter out double slashes s = s.gsub(/\\\\/, '\\') while s.index('\\\\') # Keep the trailing slash if exists trailing_s = ('\\' if s =~ /\\$/) || '' # Check the items (fie/dir) individually s = s.split(/\\/) # Parse the path prefix prefix = (s[0] || '').gsub(/[\*<>\?\/]/, '') # Delete the original prefix. We want the new one later. s.delete_at(0) # Filter out all the reserved characters s.map! {|e| e.gsub(/["\*:<>\?\\\/|]/, '') } # Put the modified prefix back s.insert(0, prefix) # And then safely join the items s *= '\\' # Add the trailing slash back if exists s << trailing_s end |