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 #4326

Merged
merged 1 commit into from
Aug 26, 2020

Conversation

dra27
Copy link
Member

@dra27 dra27 commented Aug 20, 2020

This is apparently a piece of lost history on my part, but it's resurfaced in #4325. Empty strings cause corrupt environment files, since two tabs are written in a row which are of course lexed as a single piece of whitespace.

For better or worse, my solution in 2016 was to write an empty string as @. The ambiguity with the string "@" is resolved by writing that as \@ (since the format already allows \ to escape any character.

This can go on 2.0 with one caveat - it would mean that any environment updates which intentionally set a value to be @ will now be empty. That seems unlikely, but it may be reason enough to fix this for 2.1 only.

Empty strings cause corrupt environment files, since two tabs are
written in a row which are of course lexed as a single piece of
whitespace.

Alter the format so that the @ symbol on its own means an empty string
(I'd have used something closer to $\epsilon$, but it'd never be
portable...). The single string @ is represented by \@.

Signed-off-by: David Allsopp <david.allsopp@metastack.com>
Copy link
Member

@AltGr AltGr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change seems fine;
one thing I am still not very comfortable about is that we don't support unsetting variables (this is particularly true for opam env --revert), and we set them to the empty string instead. It has more or less worked until now, and fixing it would need specific variable-unsetting code for all supported shells with all the pitfalls that involves, which is why it's still like that.

The reason I mention it here is that maybe we should provision a syntax for that as well (at first when @rjbou told me about this PR I thought that's what the @ syntax was about)

@rjbou rjbou merged commit f349d18 into ocaml:2.0 Aug 26, 2020
@dra27 dra27 deleted the empty-environment-vars branch September 7, 2020 09:43
@dra27
Copy link
Member Author

dra27 commented Sep 7, 2020

Windows doesn't support empty environment variables, so for the most part I think it's better to (try to) head towards a world where we treat "unset" and "empty" as the same thing.

@dra27
Copy link
Member Author

dra27 commented Sep 7, 2020

Has this been cherry-picked to master?

@rjbou rjbou modified the milestones: 2.1.0~beta, 2.0.8 Sep 14, 2020
@rjbou
Copy link
Collaborator

rjbou commented Sep 14, 2020

Nop, not yet

dra27 pushed a commit to dra27/opam that referenced this pull request Sep 16, 2021
Handle empty environment variable updates
rjbou added a commit to rjbou/opam that referenced this pull request Sep 20, 2021
Handle empty environment variable updates
rjbou added a commit to rjbou/opam that referenced this pull request Oct 6, 2021
Handle empty environment variable updates
rjbou added a commit to rjbou/opam that referenced this pull request Oct 21, 2021
Handle empty environment variable updates
@dra27 dra27 mentioned this pull request Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.opam-switch/environment file format is ambiguous and can lead to errors
3 participants