Project

General

Profile

Actions

Feature #16741

open

Implement Shellwords.shellescape correctly for Windows

Feature #16741: Implement Shellwords.shellescape correctly for Windows

Added by abobrikovich (Alexander Bobrikovich) over 5 years ago. Updated over 5 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:97611]

Description

shellwords module was originally designed and developed for *NIX, and currently works like this:

require 'shellwords'

Shellwords.shellescape("/home/me/test with space.txt")
# => "/home/me/test\\ with\\ space.txt"

Shellwords.shellescape("C:\Program Files")
# => "C:Program\\ Files"

I think it's a good opportunity to extend it to support Windows. According to [2], it looks like using quotations is the only option for paths used in a batch script that have space inside. I propose:

Shellwords.shellescape("C:\Program Files")
# => "\"C:\Program Files\""

Links

  1. https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
  2. https://superuser.com/a/962816/245944
  3. https://ss64.com/nt/syntax-esc.html

Updated by znz (Kazuhiro NISHIYAMA) over 5 years ago Actions #1 [ruby-core:97613]

I think adding Shellwords.cmdescape is better than changing Shellwords.shellescape.

Some environments on Windows support both bash and cmd.

Updated by mame (Yusuke Endoh) over 5 years ago Actions #2 [ruby-core:97614]

I agree with @znz (Kazuhiro NISHIYAMA). IMO, a gem named cmdwords or something would be a good start for the feature instead of directly extending shellwords.

Updated by sawa (Tsuyoshi Sawada) over 5 years ago Actions #3

  • Subject changed from Implement Shellwords.shellescape correctly on Windows to Implement Shellwords.shellescape correctly for Windows
  • Description updated (diff)

Updated by nobu (Nobuyoshi Nakada) over 5 years ago Actions #4 [ruby-core:97615]

I'm curious for what purpose you need to escape paths.
To pass it to another program, it is better to spawn or system with split array.

Actions

Also available in: PDF Atom