Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[FIXED JENKINS-25511] [JENKINS-17309] Reverted XML escaping of message.
Browse files Browse the repository at this point in the history
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 e001040
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 24 deletions.
Expand Up @@ -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 = "-";
Expand Down
@@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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());
}
}

Expand Down
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

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

import static org.junit.Assert.*;

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

Expand All @@ -10,6 +8,8 @@

import com.google.common.collect.Lists;

import static org.junit.Assert.*;

/**
* Tests the class {@link AbstractAnnotation}.
*
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e001040

Please sign in to comment.