Opened 12 years ago
Closed 12 years ago
#1012 closed defect (fixed)
getopt-long discards doublequotes and option values after whitespace characters
| Reported by: | evhan | Owned by: | Ivan Raikov | 
|---|---|---|---|
| Priority: | minor | Milestone: | someday | 
| Component: | extensions | Version: | 4.8.x | 
| Keywords: | getopt-long | Cc: | |
| Estimated difficulty: | 
Description
getopt-long contains logic for handling doublequote-wrapped option values. However, this interferes with option values containing internal doublequotes and makes it impossible to pass arguments that explicitly include surrounding doublequotes. I believe argument quoting is adequately resolved by the shell before option values are ever in CHICKEN's control (i.e. in the command-line-arguments parameter), so this logic is unnecessary and the attached patch removes it.
getopt-long also discards any characters in option values after and including the first whitespace character (that is, those in srfi-14's char-set:blank). This makes it impossible to pass arguments containing spaces without intentionally double-quoting them (to activate the doublequote-handling logic, which I believe is incorrect as noted above).
Finally, getopt-long accepts only a small set of characters in option values, raising an error on any characters not in that set. I believe this is an unnecessary restriction, so the patch removes it as well.
;;
;; Given the following (and assuming a common shell):
;;
(pp (command-line-arguments))
(pp (getopt-long (command-line-arguments) '((foo (value #t)))))
;;
;; $ ./test --foo="\"bar\""
;; ("--foo=\"bar\"")
;; ((@) (foo . "bar"))
;;
;; $ ./test --foo="bar baz qux"
;; ("--foo=bar baz qux")
;; ((@) (foo . "bar"))
;;
;; $ ./test --foo="\"bar baz qux\""
;; ("--foo=\"bar baz qux\"")
;; ((@) (foo . "bar baz qux"))
;;
;; $ ./test --foo="\"bar baz\" qux"                                                                                 
;; ("--foo=\"bar baz\" qux")
;; ((@) (foo . "bar baz"))
;;
;; $ ./test --foo='bar"baz"qux'
;; ("--foo=bar\"baz\"qux")
;; ((@) (foo . "barbazqux"))
;;
;; $ ./test --foo='bar+baz=qux'
;; ("--foo=bar+baz=qux")
;; Error: (long-option-value) invalid option character: #\+
;;
    Attachments (1)
Change History (3)
Changed 12 years ago by
| Attachment: | simplify-long-option-value-handling.patch added | 
|---|
comment:1 Changed 12 years ago by
| Owner: | set to Ivan Raikov | 
|---|---|
| Status: | new → accepted | 
comment:2 Changed 12 years ago by
| Resolution: | → fixed | 
|---|---|
| Status: | accepted → closed | 
Hi Ivan,
This is perfect -- thank you for the consideration and quick fix, it's very appreciated.
Closing.


Hello,