[PUP-1209] Exec provider should support environment variables with empty values Created: 2013/12/20  Updated: 2018/12/19  Resolved: 2018/11/08

Status: Closed
Project: Puppet
Component/s: None
Affects Version/s: None
Fix Version/s: PUP 6.1.0

Type: Bug Priority: Normal
Reporter: redmine.exporter Assignee: Melissa Stone
Resolution: Fixed Votes: 0
Labels: community, redmine, resolved-issue-added
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template: PUP Bug Template
Epic Link: Execution API
Team: Coremunity
Sprint: Platform Core KANBAN
Release Notes: Bug Fix
Release Notes Summary: Exec provider now supports empty environment variables. Even if an environment variable is set on the system, if it is set at empty, Puppet temporarily overwrites it during execution.


The exec provider takes an environment parameter that takes either a string or an array of variables. Each variable is expressed as a pair, like "KEY=value" for example. The problem is that the code that parses this string requires a value whereas this is not strictly necessary, like "KEY=" should be perfectly acceptable. The code in Puppet::Provider::Exec.run looks like this:

if setting =~ /^(\w+)=((.|\n)+)$/
 env_name = $1
 value = $2

Simply changing the regular expression to use "*" instread of "+" for the value should work just fine:

irb(main):001:0> setting = 'KEY='
 => "KEY="
 irb(main):002:0> setting =~ /^(\w+)=((.|\n)+)$/
 => nil
 irb(main):003:0> setting =~ /^(\w+)=((.|\n)*)$/
 => 0
 irb(main):004:0> $1
 => "KEY"
 irb(main):005:0> $2
 => "" 

So, the value of empty string is exactly what was requested.

Comment by Moses Mendoza [ 2016/10/31 ]

This ticket has not been updated in some time and is now being closed due to inactivity. This isn't necessarily a statement that this ticket isn't important - other issues may have demanded precedence since it was filed, or it may have simply slipped through the cracks. If any viewer/watcher feels closing this ticket is an error, please re-open it and add a comment explaining. Our apologies in advance for any mistake on this.

Comment by Peter Souter [ 2016/12/13 ]

Re-opened and PR'd

Comment by Maggie Dreyer [ 2017/05/15 ]

PR: https://github.com/puppetlabs/puppet/pull/5426

Comment by Melissa Stone [ 2018/11/06 ]

Merged into puppet#master atĀ https://github.com/puppetlabs/puppet/commit/d41c1db1cdeb7ee3db3e4d8cb9a33cdc0ce01570

Comment by Melissa Stone [ 2018/11/08 ]

This passed CI as a part of puppet-agentĀ

Generated at Mon Dec 09 12:29:19 PST 2019 using JIRA 7.7.1#77002-sha1:e75ca93d5574d9409c0630b81c894d9065296414.