Skip to content

Commit

Permalink
Fix bad interpretation of <backslash><newline> in here-document with …
Browse files Browse the repository at this point in the history
…a quoted end marker.
  • Loading branch information
yurug committed Oct 29, 2019
1 parent 3b8b77a commit 84a786a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/hereDocument.ml
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,13 @@ end = struct
double-quote appears within "$()", "``", or "${}".
*)
let contents =
Printf.eprintf "Content = %s\n" contents;

This comment has been minimized.

Copy link
@Niols

Niols Oct 29, 2019

Member

Is that kept here on purpose or is that debug?

This comment has been minimized.

Copy link
@yurug

yurug Oct 29, 2019

Author Contributor

Oups.

if delimiter_info.quoted then
QuoteRemoval.backslash_as_in_doublequotes contents
else
contents
in
Printf.eprintf "Content = %s\n" contents;
let contents, cst =
remove_contents_suffix doc_end end_marker contents cst
in
Expand Down
8 changes: 3 additions & 5 deletions src/quoteRemoval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,18 @@ type backslash_automaton_state = Default | Backslash
let backslash_as_in_doublequotes s =
let n = String.length s in
let b = Buffer.create n in
let i = ref 0 and
state = ref Default in
let i = ref 0 and state = ref Default in
let keep () = Buffer.add_char b s.[!i]; incr i
and pushbackslash () = Buffer.add_char b '\\'
and skip () = incr i in
while !i<n do
while !i < n do
match !state with
| Default ->
if s.[!i] = '\\'
then begin state := Backslash; skip () end
else keep ()
| Backslash -> begin
if s.[!i] = '\n' then skip () (* FIXME: can that happen? *)
else if List.mem s.[!i] ['$'; '\''; '"'; '\\'] then keep ()
if List.mem s.[!i] ['$'; '\''; '"'; '\\'] then keep ()
else begin pushbackslash(); keep () end;
state := Default
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
],
[
"Word",
"abc ` def\nghi jkl\n",
"abc ` def\nghi \\\njkl\n",
[ [ "WordLiteral", "abc ` def\nghi \\\njkl\n" ] ]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
],
[
"Word",
"Here document not expanded, may be unbalanced ' \" $(\nand a backslash at the end of the line is NOT removed ",
"Here document not expanded, may be unbalanced ' \" $(\nand a backslash at the end of the line is NOT removed \\\n",
[
[
"WordLiteral",
Expand Down

0 comments on commit 84a786a

Please sign in to comment.