From d9dcc8cc2deb6d587987315d2c0ca18511d9ee7e Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Fri, 17 Feb 2017 17:18:10 -0500 Subject: [PATCH] fixed UTF-8 BOM bug --- .../dependencycheck/xml/pom/PomParser.java | 13 +- .../dependencycheck/xml/pom/PomUtilsTest.java | 5 + .../src/test/resources/jmockit-1.26.pom | 268 ++++++++++++++++++ 3 files changed, 281 insertions(+), 5 deletions(-) create mode 100644 dependency-check-core/src/test/resources/jmockit-1.26.pom diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/xml/pom/PomParser.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/xml/pom/PomParser.java index fd4595737..5218e3d7a 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/xml/pom/PomParser.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/xml/pom/PomParser.java @@ -26,6 +26,8 @@ import java.io.InputStreamReader; import java.io.Reader; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; +import org.apache.commons.io.ByteOrderMark; +import org.apache.commons.io.input.BOMInputStream; import org.owasp.dependencycheck.utils.XmlUtils; import org.slf4j.Logger; @@ -88,14 +90,15 @@ public class PomParser { final SAXParser saxParser = XmlUtils.buildSecureSaxParser(); final XMLReader xmlReader = saxParser.getXMLReader(); xmlReader.setContentHandler(handler); - final Reader reader = new InputStreamReader(inputStream, "UTF-8"); + BOMInputStream bomStream = new BOMInputStream(inputStream); + ByteOrderMark bom = bomStream.getBOM(); + String defaultEncoding = "UTF-8"; + String charsetName = bom == null ? defaultEncoding : bom.getCharsetName(); + final Reader reader = new InputStreamReader(bomStream, charsetName); final InputSource in = new InputSource(reader); xmlReader.parse(in); return handler.getModel(); - } catch (ParserConfigurationException ex) { - LOGGER.debug("", ex); - throw new PomParseException(ex); - } catch (SAXException ex) { + } catch (ParserConfigurationException | SAXException ex) { LOGGER.debug("", ex); throw new PomParseException(ex); } catch (FileNotFoundException ex) { diff --git a/dependency-check-core/src/test/java/org/owasp/dependencycheck/xml/pom/PomUtilsTest.java b/dependency-check-core/src/test/java/org/owasp/dependencycheck/xml/pom/PomUtilsTest.java index adedf1b35..f16c05724 100644 --- a/dependency-check-core/src/test/java/org/owasp/dependencycheck/xml/pom/PomUtilsTest.java +++ b/dependency-check-core/src/test/java/org/owasp/dependencycheck/xml/pom/PomUtilsTest.java @@ -38,6 +38,11 @@ public class PomUtilsTest extends BaseTest { String expResult = "Direct Web Remoting"; Model result = PomUtils.readPom(file); assertEquals(expResult, result.getName()); + + file = BaseTest.getResourceAsFile(this, "jmockit-1.26.pom"); + expResult = "Main"; + result = PomUtils.readPom(file); + assertEquals(expResult, result.getName()); } } diff --git a/dependency-check-core/src/test/resources/jmockit-1.26.pom b/dependency-check-core/src/test/resources/jmockit-1.26.pom new file mode 100644 index 000000000..590d69b63 --- /dev/null +++ b/dependency-check-core/src/test/resources/jmockit-1.26.pom @@ -0,0 +1,268 @@ + + + 4.0.0 + + org.jmockitjmockit1.26 + jar + + Main + + JMockit is a Java toolkit for automated developer testing. + It contains mocking and faking APIs and a code coverage tool, supporting both JUnit and TestNG. + The mocking API allows all kinds of Java code, without testability restrictions, to be tested + in isolation from selected dependencies. + + http://www.jmockit.org + + + The MIT License + http://www.opensource.org/licenses/mit-license.php + + + + Rogério Liesenfeld + + 2006 + + https://github.com/jmockit/jmockit1 + scm:git:https://github.com/jmockit/jmockit1 + + + GitHub Issues + https://github.com/jmockit/jmockit1/issues + + + + JMockit Users + http://groups.google.com/group/jmockit-users + jmockit-users@googlegroups.com + + + + + UTF-8 + + + + src + test + + + . + + META-INF/services/org.junit.platform.engine.TestEngine + META-INF/services/org.testng.ITestNGListener + + + + src + + **/*.css + **/*.js + **/*.png + + + + .. + + LICENSE.txt + NOTICE.txt + + + + + + test + **/*.zip + + + + + maven-enforcer-plugin1.4.1 + + + enforce + + + 1.8 + 3.3.1 + + + + + + + + maven-compiler-plugin3.5.1 + + UTF-8 + 1.61.6 + -Xlint:none + false + + + + maven-jar-plugin2.6 + + + false + + mockit.coverage.CodeCoverage + mockit.internal.startup.Startup + mockit.internal.startup.Startup + true + true + ${project.version} + + + + + + + maven-source-plugin3.0.0 + + + * + **/*.css + **/*.js + + + + + attach-sources + jar-no-fork + + + + + maven-javadoc-plugin2.10.3 + + UTF-8 + true + true + true + true + true + false + 1.7 + JMockit Toolkit API + JMockit Toolkit API Documentation + ${project.basedir}/../../jmockit.github.io/api1x/stylesheet.css + ${project.basedir}/../../jmockit.github.io/api1x/overview.html +
JMockit Home]]>
+
JMockit Home]]>
+ true + true + ${basedir}/src + none + -Xdoclint:none mockit mockit.integration.junit4 +
+ + + attach-javadocs + jar + + +
+ + maven-surefire-plugin2.19.1 + + true + true + alphabetical + + + + JUnit-tests + test + test + + ${skipTests} + none:none + + **/*$* + **/Base*Test.class + **/JUnit4DecoratorTest.class + **/testng/*Test.class + **/MockStateBetweenTestMethodsNGTest.class + **/mockit/integration/TestedClass.class + + + + + TestNG-tests + test + test + + ${skipTests} + none:none + + **/testng/*Test.class + **/MockStateBetweenTestMethodsNGTest.class + + + **/TestNGViolatedExpectationsTest.class + + + + + + + maven-gpg-plugin1.6 + + + sign-artifacts + deploy + sign + + + + + org.sonatype.pluginsnexus-staging-maven-plugin + 1.6.7 + true + + sonatype-nexus-staging + https://oss.sonatype.org/ + true + + +
+
+ + + + com.google.code.findbugsjsr3053.0.0 + true + + + junitjunit4.12 + true + + + org.junit.jupiterjunit-jupiter-engine5.0.0-M1 + true + + + org.testngtestng6.9.10 + true + + com.google.injectguice + org.beanshellbsh + + + + javaxjavaee-api7.0 + true + + com.sun.mailjavax.mail + + + + org.springframeworkspring-web4.2.0.RELEASE + true + + +
\ No newline at end of file