Skip to content

Commit

Permalink
Merge pull request ocaml#4326 from dra27/empty-environment-vars
Browse files Browse the repository at this point in the history
Handle empty environment variable updates
  • Loading branch information
rjbou committed Oct 6, 2021
1 parent c450316 commit e038d3f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/format/opamFile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,12 @@ module LinesBase = struct
aux acc (i-1) in
aux ([],0) (len - 1)

let escape_spaces str =
let escape_spaces = function
| "" ->
"@"
| "@" ->
"\\@"
| str ->
let len = String.length str in
match find_escapes str len with
| [], _ -> str
Expand Down
12 changes: 8 additions & 4 deletions src/format/opamLineLexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ let word = Buffer.create 57

}

let normalchar = [^' ' '\t' '\n' '\\']
let normalchar = [^' ' '\t' '\r' '\n' '\\']

rule main = parse
| '\n' { Lexing.new_line lexbuf; NEWLINE }
| '\n' | "\r\n"
{ Lexing.new_line lexbuf; NEWLINE }
| [' ' '\t']+ { main lexbuf }
| ('@' normalchar*) as w '\\'
{ Buffer.reset word ; Buffer.add_string word w; escaped lexbuf }
| ('@' normalchar*) as w
{ if w = "@" then WORD "" else WORD w }
| (normalchar* as w) '\\'
{ Buffer.reset word ; Buffer.add_string word w; escaped lexbuf }
| (normalchar* as w)
| (normalchar+ as w)
{ WORD w }
| eof { EOF }

Expand All @@ -42,7 +47,6 @@ and escaped = parse
let main lexbuf =
let rec aux lines words =
match main lexbuf with
| WORD "" -> aux lines words
| WORD s -> aux lines (s::words)
| NEWLINE ->
let lines = if words = [] then lines else List.rev words::lines in
Expand Down

0 comments on commit e038d3f

Please sign in to comment.