Bug 999770

Summary: [origin_broker_86] User Env variable's value still cannot support special chars like '%' , ';'
Product: OpenShift Online Reporter: zhaozhanqi <zzhao>
Component: MasterAssignee: Ben Parees <bparees>
Status: CLOSED NOTABUG QA Contact: libra bugs <libra-bugs>
Severity: low Docs Contact:
Priority: medium    
Version: 2.xCC: bparees, xtian
Target Milestone: ---Keywords: Reopened
Target Release: ---   
Hardware: All   
OS: All   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-11-15 21:17:17 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description zhaozhanqi 2013-08-22 05:34:54 UTC
Description of problem:
if user env variable's value contain like '|',';' etc , this variable will be set to blank. 

Version-Release number of selected component (if applicable):
devenv_3683
devenv_stage_448

How reproducible:
always

Steps to Reproduce:
1. creat one app 
2. add one env variable with special charcter(for example '|') for this app
   curl -k -H 'Accept: application/xml' --user zzhao:redhat https://$instance/broker/rest/applications/479428171624072284733440/environment-variables -X POST -d name=special -d value=|/usr/bin/lesspipe.sh

3. check its env
   rhc ssh app --gear env|grep special

Actual results:
 after step 2, it will not give a response result.
 curl -k -H 'Accept: application/xml' --user zzhao:redhat https://$instance/broker/rest/applications/479428171624072284733440/environment-variables -X POST -d name=special -d value=|/usr/bin/lesspipe.sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
103  2248  102  2248    0    19   1175      9  0:00:01  0:00:01 --:--:--  2591


[zqzhao@dhcp-13-222 .openshift]$ rhc ssh zqphp --gear env|grep special
special=


Expected results:
step 2: should be give a result like 'Added environment variable 'special' to application zqphp
step 3: special=|/usr/bin/lesspipe.sh

Additional info:

Comment 1 Lili Nader 2013-08-22 06:42:01 UTC
Ravi, let me know if you need help with bug fixes

Comment 2 Ravi Sankar 2013-08-22 18:00:02 UTC
This is expected behavior.
Step-2 is interpreted by bash shell as
(a) curl -k -H 'Accept: application/xml' --user zzhao:redhat https://$instance/broker/rest/applications/479428171624072284733440/environment-variables -X POST -d name=special -d value=
(b) Output of (a) will be passed to /usr/bin/lesspipe.sh because of '|'

What you might have intended was to do this:
curl -k -H 'Accept: application/xml' --user zzhao:redhat https://$instance/broker/rest/applications/479428171624072284733440/environment-variables -X POST -d name=special -d value='|/usr/bin/lesspipe.sh' => this works.

Note: single quotes ('') was missing for the value param.

Comment 4 zhaozhanqi 2013-08-23 02:31:29 UTC
RE-open this bug, ';' '%' still cannot be parsed 
 
1)curl -k -H 'Accept: application/xml' --user zzhao:redhat https://$instance/broker/rest/applications/8ab67c8c0b9811e3928e22000ab227cc/environment-variables/foo -X PUT  -d value='rs=0:di=01;34:ln=01'

$ rhc ssh zqphp --gear env |grep foo
foo=rs=0:di=01

2)curl -k -H 'Accept: application/xml' --user zzhao:redhat https://$instance/broker/rest/applications/8ab67c8c0b9811e3928e22000ab227cc/environment-variables/foo -X PUT  -d value='|/usr/bin/lesspipe.sh %s'

it will return errors '<h1>
  ArgumentError
    in EnvironmentVariablesController#update
</h1>
<pre>invalid %-encoding (|/usr/bin/lesspipe.sh %s)</pre>'

FIY:
the following env variable are got from 'env', so we need to support this situation.

LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;0
LESSOPEN=|/usr/bin/lesspipe.sh %s

Comment 5 Ben Parees 2013-11-15 21:15:29 UTC
; and % are special characters in html form posting (which is the format you're using with the -d curl commands) so you'd need to escape them, eg:

curl -k -H 'Accept: application/xml' --user test:test https://ec2-54-205-123-138.compute-1.amazonaws.com/broker/rest/domain/test/application/jbossews/environment-variables -X POST -d name=foo8 -d value='bar%3B'

yields:
rhc ssh jbossews --gear env | grep foo8
foo8=bar;

and
curl -k -H 'Accept: application/xml' --user test:test https://ec2-54-205-123-138.compute-1.amazonaws.com/broker/rest/domain/test/application/jbossews/environment-variables -X POST -d name=foo9 -d value='bar%25'

yields
rhc ssh jbossews --gear env | grep foo9
foo9=bar%

Note that I also tested the rhc commands directly and they handle the escaping for you (well they appear to use json so html form encoding is not an issue):

rhc env set test=test%test --app jbossews
Setting environment variable(s) ... done
rhc env show test --app jbossews
test=test%test

# note in this case i had to quote the value to avoid the shell processing the ;
rhc env set test='test;test' --app jbossews
Setting environment variable(s) ... done
rhc env show test --app jbossews
test=test;test