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

Fix for RedHat 8 (env vars that are functions) #26

Merged
merged 1 commit into from
May 27, 2022
Merged

Fix for RedHat 8 (env vars that are functions) #26

merged 1 commit into from
May 27, 2022

Conversation

javierggt
Copy link
Contributor

@javierggt javierggt commented May 27, 2022

Description

This is a fix for #25. In the end it is easy.

The source of the problem is that there are multi-line environmental variables (functions, actually), and the "parsing" of the environment wrongly matches lines within these multi-line variables as if they were variable definitions.

printenv indents the contents of these functions (the inner-scope lines start with a space). A normal variable definition does not start with space. Therefore, the solution is to ignore lines starting with space.

That is: replace re.search(..., s.strip()) by re.match(..., s.rstrip())

Fixes #25

Interface impacts

None

Testing

When doing tests, verified that tests pass in this PR and fail in master.

Unit tests

  • Linux (rh8)

Independent check of unit tests by @taldcroft

  • Mac
  • Linux (CentOS-7, kady)

Functional tests

tried the specific test in #25:

from Ska.Shell import getenv, bash, run_shell
envs = getenv('export TEST_ENV_VARA="hello"')
bash('echo $TEST_ENV_VARA', env=envs)

@taldcroft also confirmed this functional test on han8-v (RH8) and kady (CentOS-7)

Copy link
Member

@taldcroft taldcroft left a comment

Choose a reason for hiding this comment

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

Awesome!

@taldcroft
Copy link
Member

I did independent checks and all looks good.

@taldcroft taldcroft changed the title Fix for rh8 (env vars that are functions) Fix for RedHat 8 (env vars that are functions) May 27, 2022
@javierggt javierggt merged commit e6094b7 into master May 27, 2022
@javierggt javierggt deleted the rh8 branch May 27, 2022 13:27
@jeanconn
Copy link
Contributor

jeanconn commented Jun 1, 2022

It looks like this fix isn't actually needed on owen-v, but still seems fine.

@javierggt javierggt mentioned this pull request Jun 1, 2022
@javierggt javierggt mentioned this pull request Aug 10, 2022
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.

Output of printenv should be sanitized before parsing it
3 participants