[
https://issues.apache.org/jira/browse/NIFI-5525?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16656455#comment-16656455
]
ASF GitHub Bot commented on NIFI-5525:
--------------------------------------
GitHub user pvillard31 opened a pull request:
https://github.com/apache/nifi/pull/3092
NIFI-5525 - CSVRecordReader fails with StringIndexOutOfBoundsExceptio…
…n when field is a double quote
Thank you for submitting a contribution to Apache NiFi.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
### For all changes:
- [ ] Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
- [ ] Does your PR title start with NIFI-XXXX where XXXX is the JIRA number
you are trying to resolve? Pay particular attention to the hyphen "-" character.
- [ ] Has your PR been rebased against the latest commit within the target
branch (typically master)?
- [ ] Is your initial contribution a single, squashed commit?
### For code changes:
- [ ] Have you ensured that the full suite of tests is executed via mvn
-Pcontrib-check clean install at the root nifi folder?
- [ ] Have you written or updated unit tests to verify your changes?
- [ ] If adding new dependencies to the code, are these dependencies
licensed in a way that is compatible for inclusion under [ASF
2.0](http://www.apache.org/legal/resolved.html#category-a)?
- [ ] If applicable, have you updated the LICENSE file, including the main
LICENSE file under nifi-assembly?
- [ ] If applicable, have you updated the NOTICE file, including the main
NOTICE file found under nifi-assembly?
- [ ] If adding new Properties, have you added .displayName in addition to
.name (programmatic access) for each of the new properties?
### For documentation related changes:
- [ ] Have you ensured that format looks appropriate for the output in
which it is rendered?
### Note:
Please ensure that once the PR is submitted, you check travis-ci for build
issues and submit an update to your PR as soon as possible.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/pvillard31/nifi NIFI-5525
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/nifi/pull/3092.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #3092
----
commit 97ae7f8d7f5c03bf63ebcc7fee74780f9abf7954
Author: Pierre Villard <pierre.villard.fr@...>
Date: 2018-10-19T08:44:00Z
NIFI-5525 - CSVRecordReader fails with StringIndexOutOfBoundsException when
field is a double quote
----
> CSVRecordReader fails with StringIndexOutOfBoundsException when field is a
> double quote
> ---------------------------------------------------------------------------------------
>
> Key: NIFI-5525
> URL: https://issues.apache.org/jira/browse/NIFI-5525
> Project: Apache NiFi
> Issue Type: Bug
> Components: Core Framework
> Affects Versions: 1.7.1
> Reporter: Vadim
> Assignee: Pierre Villard
> Priority: Major
> Labels: easyfix, pull-request-available
> Fix For: 1.8.0
>
>
> *Bug description:*
> When trying to parse a CSV file given in RFC4180 format and one of its fields
> is a double quote, CSVRecordReader fails with the following exception:
> {quote}java.lang.StringIndexOutOfBoundsException: String index out of range:
> -1
> at java.lang.String.substring(String.java:1967)
> at
> org.apache.nifi.csv.AbstractCSVRecordReader.convert(AbstractCSVRecordReader.java:82)
> at org.apache.nifi.csv.CSVRecordReader.nextRecord(CSVRecordReader.java:102)
> at org.apache.nifi.serialization.RecordReader.nextRecord(RecordReader.java:50)
> at
> org.apache.nifi.csv.TestCSVRecordReader.testQuote(TestCSVRecordReader.java:610)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
> at
> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
> at
> com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
> at
> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
> at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
> {quote}
>
> Note, that according to RFC4180:
>
> If double-quotes are used to enclose fields, then a double-quote
> appearing inside a field must be escaped by preceding it with
> another double quote.
> [https://tools.ietf.org/html/rfc4180#page-2]
>
> Then a field whose value is a double quote character would be encoded like
> this:
> """"
> (4 double quote characters)
> *How to reproduce*
> Add the following method to TestCSVRecordReader.java and run the test:
>
> {code:java}
> @Test
> public void testQuote() throws IOException, MalformedRecordException {
> final CSVFormat format =
> CSVFormat.RFC4180.withFirstRecordAsHeader().withTrim().withQuote('"');
> final String text = "\"name\"\n\"\"\"\"";
> final List<RecordField> fields = new ArrayList<>();
> fields.add(new RecordField("name", RecordFieldType.STRING.getDataType()));
> final RecordSchema schema = new SimpleRecordSchema(fields);
> try (final InputStream bais = new
> ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
> final CSVRecordReader reader = new CSVRecordReader(bais,
> Mockito.mock(ComponentLog.class), schema, format, true, false,
> RecordFieldType.DATE.getDefaultFormat(),
> RecordFieldType.TIME.getDefaultFormat(),
> RecordFieldType.TIMESTAMP.getDefaultFormat(), StandardCharsets.UTF_8.name()))
> {
> final Record record = reader.nextRecord();
> final String name = (String)record.getValue("name");
> assertEquals("\"", name);
> }
> }
> {code}
>
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)