This is an automated email from the ASF dual-hosted git repository. fschumacher pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/jmeter.git
The following commit(s) were added to refs/heads/master by this push: new 3af59b9 Skip BOM on files opened through FileServer 3af59b9 is described below commit 3af59b954cd3d271fb189080036baddd4b4f9d31 Author: Felix Schumacher <felix.schumac...@internetallee.de> AuthorDate: Thu Aug 15 13:52:32 2019 +0200 Skip BOM on files opened through FileServer Use the BOM to detect the character encoding, if none is given explicitly. Reported by Havlicek Honza (havlicek.honza at gmail.com) Bugzilla Id: 63643 --- .../src/main/java/org/apache/jmeter/services/FileServer.java | 5 ++++- .../test/groovy/org/apache/jmeter/services/FileServerSpec.groovy | 9 +++++++++ .../resources/org/apache/jmeter/services/testfiles/bomData.csv | 1 + xdocs/changes.xml | 3 +++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/core/src/main/java/org/apache/jmeter/services/FileServer.java b/src/core/src/main/java/org/apache/jmeter/services/FileServer.java index 681a178..0cb63bd 100644 --- a/src/core/src/main/java/org/apache/jmeter/services/FileServer.java +++ b/src/core/src/main/java/org/apache/jmeter/services/FileServer.java @@ -35,6 +35,7 @@ import java.util.Map; import java.util.concurrent.ThreadLocalRandom; import org.apache.commons.collections.ArrayStack; +import org.apache.commons.io.input.BOMInputStream; import org.apache.jmeter.gui.JMeterFileFilter; import org.apache.jmeter.save.CSVSaveService; import org.apache.jmeter.util.JMeterUtils; @@ -423,12 +424,14 @@ public class FileServer { if (!fileEntry.file.canRead() || !fileEntry.file.isFile()) { throw new IllegalArgumentException("File "+ fileEntry.file.getName()+ " must exist and be readable"); } - FileInputStream fis = new FileInputStream(fileEntry.file); + BOMInputStream fis = new BOMInputStream(new FileInputStream(fileEntry.file)); InputStreamReader isr = null; // If file encoding is specified, read using that encoding, otherwise use default platform encoding String charsetName = fileEntry.charSetEncoding; if(!JOrphanUtils.isBlank(charsetName)) { isr = new InputStreamReader(fis, charsetName); + } else if (fis.hasBOM()) { + isr = new InputStreamReader(fis, fis.getBOM().getCharsetName()); } else { isr = new InputStreamReader(fis); } diff --git a/src/core/src/test/groovy/org/apache/jmeter/services/FileServerSpec.groovy b/src/core/src/test/groovy/org/apache/jmeter/services/FileServerSpec.groovy index 69d020f..914bc2d 100644 --- a/src/core/src/test/groovy/org/apache/jmeter/services/FileServerSpec.groovy +++ b/src/core/src/test/groovy/org/apache/jmeter/services/FileServerSpec.groovy @@ -27,6 +27,7 @@ class FileServerSpec extends JMeterSpec { def testFile = getResourceFilePath("testfiles/unit/FileServerSpec.csv") def emptyFile = getResourceFilePath("testfiles/empty.csv") + def bomFile = getResourceFilePath("testfiles/bomData.csv") def setup() { @@ -214,4 +215,12 @@ class FileServerSpec extends JMeterSpec { .getCanonicalFile() == testFile.getCanonicalFile() } + def "skip bom at start of file and set correct encoding"() { + given: + sut.reserveFile(bomFile) + when: + def header = sut.readLine(bomFile) + then: + header == '"äöü"' + } } diff --git a/src/core/src/test/resources/org/apache/jmeter/services/testfiles/bomData.csv b/src/core/src/test/resources/org/apache/jmeter/services/testfiles/bomData.csv new file mode 100644 index 0000000..6612cc5 --- /dev/null +++ b/src/core/src/test/resources/org/apache/jmeter/services/testfiles/bomData.csv @@ -0,0 +1 @@ +"äöü" diff --git a/xdocs/changes.xml b/xdocs/changes.xml index 4c9b35e..7cd7953 100644 --- a/xdocs/changes.xml +++ b/xdocs/changes.xml @@ -106,6 +106,8 @@ to view the last release notes of version 5.1.1. <li><bug>62863</bug>Enable PKCS11 keystores for usage with KeyStore Manager. Based on patch by Clifford Harms (clifford.harms at gmail.com).</li> <li><pr>457</pr>Slight performance improvement in PoissonRandomTimer by using ThreadLocalRandom. Based on a patch by Xia Li.</li> <li><bug>62787</bug>New <code>XPath2 Assertion</code> supporting XPath2 with better performances than <code>XPath Assertion</code>. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li> + <li><bug>63643</bug>Skip BOM on files opened through <code>FileServer</code> and use the BOM to detect the character encoding, + if none is given explicitly. Reported by Havlicek Honza (havlicek.honza at gmail.com)</li> </ul> <h3>Functions</h3> @@ -224,6 +226,7 @@ to view the last release notes of version 5.1.1. <li>Brian Tully (brian.tully at acquia.com)</li> <li>Amer Ghazal (amerghazal at gmail.com)</li> <li>Stefan Seide (stefan at trilobyte-se.de)</li> + <li>Havlicek Honza (havlicek.honza at gmail.com)</li> </ul> <p> Apologies if we have omitted anyone else.