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

Malformed XML in API due to slash in element tag name

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Component/s: git-plugin
    • Labels:
      None
    • Environment:
      Jenkins ver. 1.398
      Jenkins GIT plugin 1.1.5
      Windows 7 x64

      Description

      See attached file for the broken XML generated by the Git plugin (I think).

      Notice:

      <buildsByBranchName>
      <origin/master>
      ...
      </origin/master>
      </buildsByBranchName>

      The slash in the branch name is causing the problem. Perhaps this value should be in an attribute rather than tag name?

        Issue Links

          Activity

          Hide
          brendon Brendon Van Heyzen added a comment -

          same things happens to me on jenkins v 1.399

          Show
          brendon Brendon Van Heyzen added a comment - same things happens to me on jenkins v 1.399
          Hide
          rombert rombert added a comment -

          I would be willing to provide a patch for this, given that someone can point me in the right direction.

          Show
          rombert rombert added a comment - I would be willing to provide a patch for this, given that someone can point me in the right direction.
          Hide
          jhurne jhurne added a comment - - edited

          This is actually caused by a bug in the Stapler library with how it handles exported Map properties. Basically, it uses the String representation of a the key for each entry in the map. Sometimes (as is the case with the git plugin), the key contains characters which are not valid XML. In this specific instance, the problematic map is the buildsByBranch map found in the hudson.plugins.git.util.BuildData class. The key of the map is the name of the branch, which often contains slash (origin/master). Of course "/" isn't a valid character in a Tag name.

          However, it looks like Kohsuke just released a new version (1.160) of Stapler which adds a new option to the @Exported annotation (verboseMap) which allows for switching on a more verbose, but safer mechanism for exporting maps.

          I suggest upgrading to the 1.160 release of Stapler, and modifying how the buildsByBranch map is exported to use the new property. Maybe something like:

          @Exported(verboseMap="branch/build")
          public Map<String,Build> getBuildsByBranchName()

          { return buildsByBranchName; }

          Which will generate XML similar to (I think):

          <buildsByBranchName>
          <branch>origin/master</branch>
          <build><!-- build XML here --></build>
          </buildsByBranchName>
          <buildsByBranchName>
          <branch>origin/topic-branch</branch>
          <build><!-- build XML here --></build>
          </buildsByBranchName>

          For more details on the new attribute, consult the Stapler 1.160 Javadoc.

          Show
          jhurne jhurne added a comment - - edited This is actually caused by a bug in the Stapler library with how it handles exported Map properties. Basically, it uses the String representation of a the key for each entry in the map. Sometimes (as is the case with the git plugin), the key contains characters which are not valid XML. In this specific instance, the problematic map is the buildsByBranch map found in the hudson.plugins.git.util.BuildData class. The key of the map is the name of the branch, which often contains slash (origin/master). Of course "/" isn't a valid character in a Tag name. However, it looks like Kohsuke just released a new version (1.160) of Stapler which adds a new option to the @Exported annotation (verboseMap) which allows for switching on a more verbose, but safer mechanism for exporting maps. I suggest upgrading to the 1.160 release of Stapler, and modifying how the buildsByBranch map is exported to use the new property. Maybe something like: @Exported(verboseMap="branch/build") public Map<String,Build> getBuildsByBranchName() { return buildsByBranchName; } Which will generate XML similar to (I think): <buildsByBranchName> <branch>origin/master</branch> <build><!-- build XML here --></build> </buildsByBranchName> <buildsByBranchName> <branch>origin/topic-branch</branch> <build><!-- build XML here --></build> </buildsByBranchName> For more details on the new attribute, consult the Stapler 1.160 Javadoc.
          Hide
          jpederzolli jpederzolli added a comment - - edited

          Looking at the 1.160 stapler source, it will now actually adjust the element names to be valid:

          http://java.net/projects/stapler/sources/svn/revision/1738

          Using the verboseMap property is likely preferable in many cases, but simply updating to 1.160 should resolve the malformed XML issue.

          Show
          jpederzolli jpederzolli added a comment - - edited Looking at the 1.160 stapler source, it will now actually adjust the element names to be valid: http://java.net/projects/stapler/sources/svn/revision/1738 Using the verboseMap property is likely preferable in many cases, but simply updating to 1.160 should resolve the malformed XML issue.
          Hide
          rombert rombert added a comment -

          Looks like this issue was reported again under JENKINS-8988 and fixed. Should this one be resolved as a duplicate?

          Show
          rombert rombert added a comment - Looks like this issue was reported again under JENKINS-8988 and fixed. Should this one be resolved as a duplicate?
          Hide
          kohsuke Kohsuke Kawaguchi added a comment -

          Consolidating to JENKINS-8988. Fixed in 1.405.

          Show
          kohsuke Kohsuke Kawaguchi added a comment - Consolidating to JENKINS-8988 . Fixed in 1.405.
          Hide
          docwhat Christian Höltje added a comment -

          JENKINS-8988 is going to be fixed in 1.405...which should fix this as well.

          Show
          docwhat Christian Höltje added a comment - JENKINS-8988 is going to be fixed in 1.405...which should fix this as well.

            People

            • Assignee:
              abayer abayer
              Reporter:
              sebastiaan Sebastiaan Deckers
            • Votes:
              5 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: