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 non Unicode env keys/values #640

Merged
merged 2 commits into from
Feb 10, 2025
Merged

Conversation

Jongy
Copy link
Contributor

@Jongy Jongy commented Feb 5, 2025

(disregard the code / commit message - I'll clean up & add tests once we agree on the implementation 😄 )

I hit the same issue as described in the linked ticket - with key PWD having a non-UTF-8 value ("invalid" from now on).

Technically, keys can be invalid too in Linux. The naive implementation I provided here filters out all invalid keys & values. Keys in config-rs are Strings so it always makes sense to filter invalid ones, as they won't be used by this library AFAIU.
As for values - I'm unsure if plainly ignoring invalid values is okay. If the value is set in a key that would have been used by the current config consumer, then ignoring it (as if the user did not provide a value through env) is not okay.
Ideally - the logic would be:

  1. Valid key & value - continue
  2. Invalid key - drop
  3. Invalid value - drop if key is not consumed, otherwise panic.

Let me know what you think :) I can try looking into point 3.

Resolves: #579

src/env.rs Outdated Show resolved Hide resolved
src/env.rs Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Feb 5, 2025

Pull Request Test Coverage Report for Build 13209377001

Details

  • 10 of 13 (76.92%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 65.124%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/env.rs 10 13 76.92%
Totals Coverage Status
Change from base Build 13059823868: 0.1%
Covered Lines: 943
Relevant Lines: 1448

💛 - Coveralls

@Jongy Jongy force-pushed the handle-non-utf8-env branch from aebb717 to 871c500 Compare February 6, 2025 01:07
src/env.rs Outdated Show resolved Hide resolved
src/env.rs Outdated Show resolved Hide resolved
@Jongy Jongy marked this pull request as ready for review February 6, 2025 01:13
tests/testsuite/env.rs Fixed Show fixed Hide fixed
tests/testsuite/env.rs Fixed Show fixed Hide fixed
tests/testsuite/env.rs Fixed Show fixed Hide fixed
@epage
Copy link
Contributor

epage commented Feb 6, 2025

I'm sorry, I overlooked that I was reviewing two different PRs (#641) for the same problem.

The tests in #641 were able to also cover Windows which could be nice.

src/env.rs Outdated Show resolved Hide resolved
tests/testsuite/env.rs Outdated Show resolved Hide resolved
Copy link
Contributor Author

@Jongy Jongy left a comment

Choose a reason for hiding this comment

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

Thanks for the review @epage , I addressed all comments.

The tests in #641 were able to also cover Windows which could be nice.

Fixed the tests here to support Windows. I haven't set up Wine to run them so I'll wait to see how it goes in the CI.

src/env.rs Outdated Show resolved Hide resolved
src/env.rs Outdated Show resolved Hide resolved
src/env.rs Outdated Show resolved Hide resolved
tests/testsuite/env.rs Show resolved Hide resolved
tests/testsuite/env.rs Outdated Show resolved Hide resolved
@Jongy Jongy force-pushed the handle-non-utf8-env branch from 871c500 to bb77333 Compare February 7, 2025 22:51
tests/testsuite/env.rs Outdated Show resolved Hide resolved
@Jongy Jongy force-pushed the handle-non-utf8-env branch 2 times, most recently from 3f67a01 to d6a5735 Compare February 7, 2025 23:39
@Jongy Jongy changed the title Handle non UTF-8 env keys/values Handle non Unicode env keys/values Feb 9, 2025
src/env.rs Outdated Show resolved Hide resolved
@Jongy Jongy force-pushed the handle-non-utf8-env branch from d6a5735 to b5d342e Compare February 10, 2025 18:54
@epage epage merged commit bbe81b5 into rust-cli:main Feb 10, 2025
15 checks passed
@epage
Copy link
Contributor

epage commented Feb 10, 2025

Thanks!

@Jongy Jongy deleted the handle-non-utf8-env branch February 10, 2025 19:59
@Jongy
Copy link
Contributor Author

Jongy commented Feb 10, 2025

Thanks again for the review, and thanks for releasing, I'll proceed to update atuin to use the new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panics when any environment variable contains non-unicode characters
3 participants