Project

General

Profile

Bug #10055

Shellwords.shellsplit() does not match POSIX sh behavior for backslashes within double-quoted strings

Added by charles-dyfis-net (Charles Duffy) almost 5 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.2.0dev (2014-07-18 trunk 46855) [x86_64-linux]
[ruby-core:63807]

Description

In POSIX sh, the following commands are identical:

printf '%s\n' hello world
printf "%s\n" hello world

However, Shellwords.shellsplit() parses them differently:

head :001 > require 'shellwords'
 => true
head :002 > Shellwords.shellsplit(%q|printf "%s\\n"|)
 => ["printf", "%sn"]
head :003 > Shellwords.shellsplit(%q|printf '%s\\n'|)
 => ["printf", "%s\\n"]

The documentation for the shellwords module claims that its parser is compatible with Bourne; however, it does not match either this 1970s-era shell language or modern POSIX sh (which is the actual specification used for /bin/sh on modern systems, and incompatible in some respects with original Bourne), both of which preserve backslashes in this context.

Associated revisions

Revision 2da5ae42
Added by knu (Akinori MUSHA) over 2 years ago

Fix the handling of the backslash in double quotes

  • lib/shellwords.rb (Shellwords#shellsplit): Fix the handling of the backslash in double quotes to conform to the standard. [ruby-core:63807] [Bug #10055]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56573 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 56573
Added by knu (Akinori MUSHA) over 2 years ago

Fix the handling of the backslash in double quotes

  • lib/shellwords.rb (Shellwords#shellsplit): Fix the handling of the backslash in double quotes to conform to the standard. [ruby-core:63807] [Bug #10055]

Revision 56573
Added by knu (Akinori MUSHA) over 2 years ago

Fix the handling of the backslash in double quotes

  • lib/shellwords.rb (Shellwords#shellsplit): Fix the handling of the backslash in double quotes to conform to the standard. [ruby-core:63807] [Bug #10055]

Revision 56573
Added by knu (Akinori MUSHA) over 2 years ago

Fix the handling of the backslash in double quotes

  • lib/shellwords.rb (Shellwords#shellsplit): Fix the handling of the backslash in double quotes to conform to the standard. [ruby-core:63807] [Bug #10055]

Revision 56573
Added by knu (Akinori MUSHA) over 2 years ago

Fix the handling of the backslash in double quotes

  • lib/shellwords.rb (Shellwords#shellsplit): Fix the handling of the backslash in double quotes to conform to the standard. [ruby-core:63807] [Bug #10055]

History

Updated by zzak (Zachary Scott) almost 5 years ago

  • Status changed from Open to Assigned
  • Assignee set to knu (Akinori MUSHA)
  • Target version set to 2.2.0

knu: do you have any thoughts on this one?

#2

Updated by knu (Akinori MUSHA) over 2 years ago

  • Status changed from Assigned to Closed

Applied in changeset r56573.


Fix the handling of the backslash in double quotes

  • lib/shellwords.rb (Shellwords#shellsplit): Fix the handling of the backslash in double quotes to conform to the standard. [ruby-core:63807] [Bug #10055]

Updated by knu (Akinori MUSHA) over 2 years ago

That is correct! I've fixed the implementation to conform to the standard.

Also available in: Atom PDF