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

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

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • core

      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
      

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

          Jesse Glick created issue -

          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.

          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.

          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.

          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 .

          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.

          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 .

          Jesse Glick added a comment -

          Jesse Glick added a comment - Seems https://github.com/jenkinsci/json-lib/commit/c9ba3240cc0ab47231e411ed999a32aabb51cad1 was incomplete.
          Jesse Glick made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]

          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.

          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.

          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 "[...]".

          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 " [...] ".

          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.

          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.
          Jesse Glick made changes -
          Assignee New: Kohsuke Kawaguchi [ kohsuke ]

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

              Created:
              Updated:
              Resolved: