Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle empty environment variable updates #4840

Merged
merged 1 commit into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ users)
*

## State
*
* Handle empty environment variable updates - missed cherry-pick from 2.0 [#4840 @dra27]

## Opam file format
*
Expand Down
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