Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-14827

Cannot use /usr/bin/[ as a shell script step: wrapped in "..." after save

    Details

    • Similar Issues:

      Description

      1.479-SNAPSHOT. Create a freeform project, add a shell build step, and enter

      [ -n x ]
      

      for the script. (This should pass.) Now visit config.xml and you will see

          <hudson.tasks.Shell>
            <command>&quot;[ -n x ]&quot;</command>
          </hudson.tasks.Shell>
      

      which is clearly wrong and would fail:

      [test] $ /bin/sh -xe /tmp/hudson123.sh
      + [ -n x ]
      /tmp/hudson123.sh: 2: /tmp/hudson123.sh: [ -n x ]: not found
      Build step 'Execute shell' marked build as failure
      

      Workaround:

      test -n x
      

        Attachments

          Issue Links

            Activity

            jglick Jesse Glick created issue -
            Hide
            jglick Jesse Glick added a comment -

            Not the fault of Shell - reproducible in HelloWorldBuilder: (foo) stored as is but [foo] translated to "[foo]". So some problem with form/JSON infrastructure.

            Show
            jglick Jesse Glick added a comment - Not the fault of Shell - reproducible in HelloWorldBuilder : (foo) stored as is but [foo] translated to "[foo]" . So some problem with form/JSON infrastructure.
            Hide
            jglick Jesse Glick added a comment -

            Posted request is fine, but StaplerRequest.getSubmittedForm is broken. Seems to be a bug in JSONObject; see call to JSONUtils.mayBeJSON.

            Show
            jglick Jesse Glick added a comment - Posted request is fine, but StaplerRequest.getSubmittedForm is broken. Seems to be a bug in JSONObject ; see call to JSONUtils.mayBeJSON .
            Hide
            jglick Jesse Glick added a comment -

            net.sf.json-lib:json-lib:2.4:jdk15 passes the test

            assertEquals("[foo]", JSONObject.fromObject("{x=\"[foo]\"}").getString("x"));
            

            but org.kohsuke.stapler:json-lib:2.1-rev7 fails it. Seems to have been fixed upstream in 2.2.

            Show
            jglick Jesse Glick added a comment - net.sf.json-lib:json-lib:2.4:jdk15 passes the test assertEquals( "[foo]" , JSONObject.fromObject( "{x=\" [foo]\ "}" ).getString( "x" )); but org.kohsuke.stapler:json-lib:2.1-rev7 fails it. Seems to have been fixed upstream in 2.2 .
            Show
            jglick Jesse Glick added a comment - Seems https://github.com/jenkinsci/json-lib/commit/c9ba3240cc0ab47231e411ed999a32aabb51cad1 was incomplete.
            jglick Jesse Glick made changes -
            Field Original Value New Value
            Status Open [ 1 ] In Progress [ 3 ]
            Hide
            jglick Jesse Glick added a comment -

            http://json-lib.sourceforge.net/changes-report.html#a2.2 notes "Extra quotes on string values with {} and []". Diffing 2.1 to 2.2 (there is no apparent SCM?) shows what seems to be an odd fix:

            @@ -2412,7 +2736,8 @@
                         if( value == null ){
                            return "";
                         }else{
            -               return str;
            +               String tmp = JSONUtils.stripQuotes( str );
            +               return JSONUtils.mayBeJSON( tmp ) ? tmp : str;
                         }
                      }
                   }else if( JSONUtils.isNumber( value ) ){
            @@ -2444,7 +2769,11 @@
                      throw new JSONException( "Null key." );
                   }
             
            -      this.properties.put( key, _processValue( value, jsonConfig ) );
            +      if( JSONUtils.isString( value ) && JSONUtils.mayBeJSON( String.valueOf( value ) ) ){
            +         this.properties.put( key, value );
            +      }else{
            +         this.properties.put( key, _processValue( value, jsonConfig ) );
            +      }
             
                   return this;
                }
            

            Theoretically https://github.com/aalmiray/Json-lib should show the details, though I am finding it hard to follow the history there - meaningless commit messages, no tags.

            Show
            jglick Jesse Glick added a comment - http://json-lib.sourceforge.net/changes-report.html#a2.2 notes "Extra quotes on string values with {} and []". Diffing 2.1 to 2.2 (there is no apparent SCM?) shows what seems to be an odd fix: @@ -2412,7 +2736,8 @@ if ( value == null ){ return ""; } else { - return str; + String tmp = JSONUtils.stripQuotes( str ); + return JSONUtils.mayBeJSON( tmp ) ? tmp : str; } } } else if ( JSONUtils.isNumber( value ) ){ @@ -2444,7 +2769,11 @@ throw new JSONException( "Null key." ); } - this .properties.put( key, _processValue( value, jsonConfig ) ); + if ( JSONUtils.isString( value ) && JSONUtils.mayBeJSON( String .valueOf( value ) ) ){ + this .properties.put( key, value ); + } else { + this .properties.put( key, _processValue( value, jsonConfig ) ); + } return this ; } Theoretically https://github.com/aalmiray/Json-lib should show the details, though I am finding it hard to follow the history there - meaningless commit messages, no tags.
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Jesse Glick
            Path:
            src/main/jdk15/net/sf/json/JSONArray.java
            src/main/jdk15/net/sf/json/JSONObject.java
            src/test/java/net/sf/json/TestJSONArray.java
            src/test/java/net/sf/json/TestJSONObject.java
            http://jenkins-ci.org/commit/json-lib/71809a892de86906299898c9cae8ced6bf278141
            Log:
            JENKINS-14827 Misinterpretation of "[...]".

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: src/main/jdk15/net/sf/json/JSONArray.java src/main/jdk15/net/sf/json/JSONObject.java src/test/java/net/sf/json/TestJSONArray.java src/test/java/net/sf/json/TestJSONObject.java http://jenkins-ci.org/commit/json-lib/71809a892de86906299898c9cae8ced6bf278141 Log: JENKINS-14827 Misinterpretation of " [...] ".
            Hide
            jglick Jesse Glick added a comment -

            I committed 71809a8 in our fork which seems to fix the problem, but am not sure what I might be missing. Anyway, if you like the fix please release, and use in Stapler / Jenkins.

            Show
            jglick Jesse Glick added a comment - I committed 71809a8 in our fork which seems to fix the problem, but am not sure what I might be missing. Anyway, if you like the fix please release, and use in Stapler / Jenkins.
            jglick Jesse Glick made changes -
            Assignee Kohsuke Kawaguchi [ kohsuke ]
            sogabe sogabe made changes -
            Link This issue is related to JENKINS-14542 [ JENKINS-14542 ]
            Hide
            sogabe sogabe added a comment -

            It works for me.

            Show
            sogabe sogabe added a comment - It works for me.
            Hide
            jglick Jesse Glick added a comment -

            @sogabe: just checked and it is still broken in 1.492. No one has released the patched json-lib much less integrated it into Stapler and then Jenkins. IIRC Kohsuke was going to try to rebase json-lib against upstream since our version is quite old.

            Show
            jglick Jesse Glick added a comment - @sogabe: just checked and it is still broken in 1.492. No one has released the patched json-lib much less integrated it into Stapler and then Jenkins. IIRC Kohsuke was going to try to rebase json-lib against upstream since our version is quite old.
            Hide
            sogabe sogabe added a comment -

            @jglick: I have installed json-lib 2.1-rev8-SNAPSHOT, which contains your patch locally and re-built jenkins with it.it works.
            It is good idea to rebase json-lib, if it takes a long time, we should release it.

            Show
            sogabe sogabe added a comment - @jglick: I have installed json-lib 2.1-rev8-SNAPSHOT, which contains your patch locally and re-built jenkins with it.it works. It is good idea to rebase json-lib, if it takes a long time, we should release it.
            Hide
            kohsuke Kohsuke Kawaguchi added a comment -

            I believe the fix is now integrated with json-lib:2.4-jenkins-1 getting into the trunk.

            Show
            kohsuke Kohsuke Kawaguchi added a comment - I believe the fix is now integrated with json-lib:2.4-jenkins-1 getting into the trunk.
            kohsuke Kohsuke Kawaguchi made changes -
            Status In Progress [ 3 ] Resolved [ 5 ]
            Resolution Fixed [ 1 ]
            Hide
            jglick Jesse Glick added a comment -

            Does seem to be fixed now.

            Show
            jglick Jesse Glick added a comment - Does seem to be fixed now.
            jglick Jesse Glick made changes -
            Link This issue is duplicated by JENKINS-13856 [ JENKINS-13856 ]
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Jesse Glick
            Path:
            changelog.html
            http://jenkins-ci.org/commit/jenkins/f8f9462b6c4ed1c83da9fed53e88fe0b8d034890
            Log:
            JENKINS-14827 Noting.

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: changelog.html http://jenkins-ci.org/commit/jenkins/f8f9462b6c4ed1c83da9fed53e88fe0b8d034890 Log: JENKINS-14827 Noting.
            Hide
            dogfood dogfood added a comment -

            Integrated in jenkins_main_trunk #2453
            JENKINS-14827 Noting. (Revision f8f9462b6c4ed1c83da9fed53e88fe0b8d034890)

            Result = SUCCESS
            Jesse Glick : f8f9462b6c4ed1c83da9fed53e88fe0b8d034890
            Files :

            • changelog.html
            Show
            dogfood dogfood added a comment - Integrated in jenkins_main_trunk #2453 JENKINS-14827 Noting. (Revision f8f9462b6c4ed1c83da9fed53e88fe0b8d034890) Result = SUCCESS Jesse Glick : f8f9462b6c4ed1c83da9fed53e88fe0b8d034890 Files : changelog.html
            jglick Jesse Glick made changes -
            Link This issue is duplicated by JENKINS-17174 [ JENKINS-17174 ]
            danielbeck Daniel Beck made changes -
            Link This issue is duplicated by JENKINS-12576 [ JENKINS-12576 ]
            rtyler R. Tyler Croy made changes -
            Workflow JNJira [ 145528 ] JNJira + In-Review [ 191530 ]

              People

              • Assignee:
                kohsuke Kohsuke Kawaguchi
                Reporter:
                jglick Jesse Glick
              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: