[
https://issues.apache.org/jira/browse/CSV-288?focusedWorklogId=727617&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-727617
]
ASF GitHub Bot logged work on CSV-288:
--------------------------------------
Author: ASF GitHub Bot
Created on: 15/Feb/22 19:05
Start Date: 15/Feb/22 19:05
Worklog Time Spent: 10m
Work Description: angusdev opened a new pull request #216:
URL: https://github.com/apache/commons-csv/pull/216
Jira Issue: https://issues.apache.org/jira/browse/CSV-288
When checking if last token is delimiter in below line of code
```java
// did we reach eof during the last iteration already ? EOF
if (isEndOfFile(lastChar) || !isDelimiter(lastChar) && isEndOfFile(c)) {
```
`isDelimiter(lastChar)` unintentionally advance the buffer pointer and
consume the first `"|"` when it comes to the `"b"` in `"a||b||c"` (lastChar is
`"|"`, nextChar is also `"|"`, make it `"||"`). Subsequent read will see `"|c"`
instead of `"||c"` so the second token is `"b|c"`
To fix it, create a new indicator `isLastTokenDelimiter` instead of using
`isDelimiter(lastChar)`, the indicator is set/reset in `isDelimiter()`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 727617)
Time Spent: 20m (was: 10m)
> String delimiter (||) is not working as expected.
> -------------------------------------------------
>
> Key: CSV-288
> URL: https://issues.apache.org/jira/browse/CSV-288
> Project: Commons CSV
> Issue Type: Bug
> Reporter: Santhsoh
> Priority: Major
> Time Spent: 20m
> Remaining Estimate: 0h
>
> Steps to reproduce :
> 1. Parse CSV file with || as delimiter and having empty columns
> 2. Print the CSVRecord resulting from CSVParser
>
> //Expected : a,b,c,d,,f,g
> // Actual : a,b|c,d,|f,g
> public static void main(String[] args) throws Exception\{
> String row = "a||b||c||d||||f||g";
> StringBuilder stringBuilder = new StringBuilder();
> try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder,
> CSVFormat.EXCEL);
> CSVParser csvParser = CSVParser.parse(new StringInputStream(row),
> StandardCharsets.UTF_8,
> CSVFormat.Builder.create().setDelimiter("||").build())) {
> for (CSVRecord csvRecord : csvParser) {
> for (int i = 0; i < csvRecord.size(); i++) {
> csvPrinter.print(csvRecord.get(i));
> }
> System.out.println(stringBuilder.toString());
> //Expected : a,b,c,d,,f,g
> // Actual : a,b|c,d,|f,g
> }
> }
> }
> With the snippet provided above, actual value is not same as expected value
--
This message was sent by Atlassian Jira
(v8.20.1#820001)