Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
[FIXED JENKINS-25511] [JENKINS-17309] Reverted XML escaping of message.
Revert of fix for JENKINS-17309. Previous solution was too aggressive, it makes sense to escape only messages from parsers that parse non-XML files. XML parsers should not escape entities at all.
AbstractAnnotation never escapes entities now, only GCC parser escapes and invokes constructor with escaped message.
  • Loading branch information
uhafner committed Nov 16, 2014
1 parent 262f3c7 commit e001040655c1b7018019a3179ed346b9f855c438
@@ -11,6 +11,7 @@
*
* @author Ulli Hafner
*/
// FIXME: Add method that uses the specified encoding when reading the files
public abstract class AbstractPackageDetector implements PackageDetector {
/** Identifies an unknown package. */
protected static final String UNKNOWN_PACKAGE = "-";
@@ -1,5 +1,6 @@
package hudson.plugins.analysis.util;

import javax.annotation.CheckForNull;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -11,14 +12,11 @@
import java.util.HashSet;
import java.util.Set;

import javax.annotation.CheckForNull;

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.LineIterator;
import org.apache.commons.lang.StringUtils;

import hudson.plugins.analysis.Messages;

import hudson.util.FormValidation;

/**
@@ -98,7 +96,7 @@ public static LineIterator readFile(final String fileName, @CheckForNull final S
return IOUtils.lineIterator(stream, encoding);
}
else {
return IOUtils.lineIterator(stream, null);
return IOUtils.lineIterator(stream, Charset.defaultCharset());
}
}

@@ -2,6 +2,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@@ -30,7 +31,7 @@ public JavaPackageDetector() {
@Override
public String detectPackageName(final InputStream stream) {
try {
LineIterator iterator = IOUtils.lineIterator(stream, null);
LineIterator iterator = IOUtils.lineIterator(stream, Charset.defaultCharset());
while (iterator.hasNext()) {
String line = iterator.nextLine();
Matcher matcher = pattern.matcher(line);
@@ -6,16 +6,14 @@
import java.util.Collections;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

import com.google.common.collect.ImmutableList;

import hudson.model.Item;
import hudson.model.AbstractBuild;

import hudson.model.Item;
import hudson.plugins.analysis.Messages;
import hudson.plugins.analysis.core.AbstractAnnotationParser;
import hudson.plugins.analysis.util.PackageDetectors;
@@ -94,7 +92,7 @@ public abstract class AbstractAnnotation implements FileAnnotation, Serializable
*/
@edu.umd.cs.findbugs.annotations.SuppressWarnings("ST")
public AbstractAnnotation(final String message, final int start, final int end, final String category, final String type) {
this.message = TreeString.of(StringUtils.strip(StringEscapeUtils.escapeXml(message)));
this.message = TreeString.of(StringUtils.strip(message));
this.category = StringUtils.defaultString(category);
this.type = StringUtils.defaultString(type);

@@ -1,7 +1,5 @@
package hudson.plugins.analysis.util.model;

import static org.junit.Assert.*;

import java.util.Collections;
import java.util.List;

@@ -10,6 +8,8 @@

import com.google.common.collect.Lists;

import static org.junit.Assert.*;

/**
* Tests the class {@link AbstractAnnotation}.
*
@@ -39,19 +39,6 @@ public void testCompareTo() {
verifyOrder(warnings, false);
}

/**
* Verifies that the message contains escaped XML characters.
*
* @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-17287">Issue 17287</a>
*/
@Test
public void issue17287() {
Warning warning = new Warning(Priority.HIGH, "dereferencing pointer '<anonymous>' does break strict-aliasing rules",
0, 0, "category", "type");

assertEquals("Wrong message escaping", "dereferencing pointer &apos;&lt;anonymous&gt;&apos; does break strict-aliasing rules", warning.getMessage());
}

private void verifyOrder(final List<AbstractAnnotation> warnings, final boolean isAscending) {
int position = 0;
for (FileAnnotation warning : warnings) {

0 comments on commit e001040

Please sign in to comment.