[jira] [Commented] (CSV-213) CSVParser#iterator()#hasNext() fails
[ https://issues.apache.org/jira/browse/CSV-213?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16095718#comment-16095718 ] Gary Gregory commented on CSV-213: -- This is normal behavior with the current architecture: The {{iterator()}} API presents an object that is backed by data in the {{CSVParser}} as the parser is _streaming_ over the file. The {{CSVParser}} is like a forward-only stream. When you create a new {{Iterator}} you are only created a new view on the same position in the parser's stream. For the behavior you want, you need to open a new {{CSVParser}}. You can also abreviate the parser creation like this: {code:java} CSVParser parser = csvFormat.parse(new InputStreamReader(new FileInputStream(csvFile), StandardCharsets.UTF_8)); {code} > CSVParser#iterator()#hasNext() fails > > > Key: CSV-213 > URL: https://issues.apache.org/jira/browse/CSV-213 > Project: Commons CSV > Issue Type: Bug > Components: Parser >Affects Versions: 1.4 > Environment: linux/osx >Reporter: Lukas Vasek >Priority: Blocker > Attachments: 999751170.patch.csv > > > Hello, > with class sample below and attached fail the program fails. Problem is that > iterator wrongly computes the records. If hasNext is true then next record > should be fetched. > + wouldn't it be better to provide currentRecord also? > {code:java} > public class Test { > private static final CSVFormat csvFormat = > CSVFormat.DEFAULT > .withDelimiter(';') > .withFirstRecordAsHeader() > .withRecordSeparator('\n') > .withQuoteMode(QuoteMode.ALL); > private static Optional createEndChannel(File csvFile) { > try (Reader reader = new InputStreamReader(new > FileInputStream(csvFile), StandardCharsets.UTF_8); > CSVParser parser = new CSVParser(reader, csvFormat)) { > if (parser.iterator().hasNext()) { > System.out.println(parser.getCurrentLineNumber()); > System.out.println(parser.getRecordNumber()); > // get only first record we don't need other's > CSVRecord firstRecord = parser.iterator().next(); // this > fails > return Optional.of(null); > } > } catch (IOException e) { > throw new RuntimeException("Error while adding end channel to > csv", e); > } > return Optional.empty(); > } > public static void main(String[] args) { > createEndChannel(new File("/tmp/999751170.patch.csv")); > //createEndChannel(new File("/tmp/129441.csv")); > } > } > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)
[jira] [Updated] (CSV-213) CSVParser#iterator()#hasNext() fails
[ https://issues.apache.org/jira/browse/CSV-213?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Gary Gregory updated CSV-213: - Summary: CSVParser#iterator()#hasNext() fails (was: CSVParser#terator()#hasNext() fails) > CSVParser#iterator()#hasNext() fails > > > Key: CSV-213 > URL: https://issues.apache.org/jira/browse/CSV-213 > Project: Commons CSV > Issue Type: Bug > Components: Parser >Affects Versions: 1.4 > Environment: linux/osx >Reporter: Lukas Vasek >Priority: Blocker > Attachments: 999751170.patch.csv > > > Hello, > with class sample below and attached fail the program fails. Problem is that > iterator wrongly computes the records. If hasNext is true then next record > should be fetched. > + wouldn't it be better to provide currentRecord also? > {code:java} > public class Test { > private static final CSVFormat csvFormat = > CSVFormat.DEFAULT > .withDelimiter(';') > .withFirstRecordAsHeader() > .withRecordSeparator('\n') > .withQuoteMode(QuoteMode.ALL); > private static Optional createEndChannel(File csvFile) { > try (Reader reader = new InputStreamReader(new > FileInputStream(csvFile), StandardCharsets.UTF_8); > CSVParser parser = new CSVParser(reader, csvFormat)) { > if (parser.iterator().hasNext()) { > System.out.println(parser.getCurrentLineNumber()); > System.out.println(parser.getRecordNumber()); > // get only first record we don't need other's > CSVRecord firstRecord = parser.iterator().next(); // this > fails > return Optional.of(null); > } > } catch (IOException e) { > throw new RuntimeException("Error while adding end channel to > csv", e); > } > return Optional.empty(); > } > public static void main(String[] args) { > createEndChannel(new File("/tmp/999751170.patch.csv")); > //createEndChannel(new File("/tmp/129441.csv")); > } > } > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)
[jira] [Comment Edited] (TEXT-74) StrSubstitutor: Ability to turn off substitution in values
[ https://issues.apache.org/jira/browse/TEXT-74?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16095134#comment-16095134 ] Amey Jadiye edited comment on TEXT-74 at 7/20/17 6:13 PM: -- found the bug, you owe me a treat ! [~arendvr.com] ;) . give me some time I will raise PR with fix, I want to refactor the code as below method is very big and have bug as well. bq. private int substitute(final StrBuilder buf, final int offset, final int length, List priorVariables) }} was (Author: ameyjadiye): found the bug, you owe me a treat ! [~arendvr.com] ;) . give me some time I will raise PR with fix, I want to refactor the code as {{private int substitute(final StrBuilder buf, final int offset, final int length, List priorVariables) }} method is very big and have bug as well. > StrSubstitutor: Ability to turn off substitution in values > -- > > Key: TEXT-74 > URL: https://issues.apache.org/jira/browse/TEXT-74 > Project: Commons Text > Issue Type: Improvement >Reporter: Arend v. Reinersdorff >Priority: Minor > Labels: features > Fix For: 1.x > > > StrSubstitutor replaces variables in values. And currently there's no way to > turn this off. > Why turn it off: I want to replace some variables in a simple template. Some > of the replacement values are arbitrary user input. > At the moment I escape all dollar signs in the replacement values with "$$". > This is annoying. Especially as I use one template with variables as a value > for another variable. Here I have to escape twice. > Here's some example code. At the moment it prints: > {code} > Hello Hamburg from Hamburg > {code} > The commented line is my suggestion for this feature. If it works, it should > print: > {code} > Hello ${city} from Hamburg > {code} > {code} > // untrusted user input > String userInputName = "${city}"; > String userInputCity = "Hamburg"; > Map valueMap = new HashMap<>(); > valueMap.put("name", userInputName); > valueMap.put("city", userInputCity); > String source = "Hello ${name} from ${city}"; > StrSubstitutor strSubstitutor = new StrSubstitutor(valueMap); > // strSubstitutor.setEnableSubstitutionInValues(false); > System.out.println(strSubstitutor.replace(source)); > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)
[jira] [Commented] (TEXT-74) StrSubstitutor: Ability to turn off substitution in values
[ https://issues.apache.org/jira/browse/TEXT-74?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16095134#comment-16095134 ] Amey Jadiye commented on TEXT-74: - found the bug, you owe me a treat ! [~arendvr.com] ;) . give me some time I will raise PR with fix, I want to refactor the code as {{private int substitute(final StrBuilder buf, final int offset, final int length, List priorVariables) }} method is very big and have bug as well. > StrSubstitutor: Ability to turn off substitution in values > -- > > Key: TEXT-74 > URL: https://issues.apache.org/jira/browse/TEXT-74 > Project: Commons Text > Issue Type: Improvement >Reporter: Arend v. Reinersdorff >Priority: Minor > Labels: features > Fix For: 1.x > > > StrSubstitutor replaces variables in values. And currently there's no way to > turn this off. > Why turn it off: I want to replace some variables in a simple template. Some > of the replacement values are arbitrary user input. > At the moment I escape all dollar signs in the replacement values with "$$". > This is annoying. Especially as I use one template with variables as a value > for another variable. Here I have to escape twice. > Here's some example code. At the moment it prints: > {code} > Hello Hamburg from Hamburg > {code} > The commented line is my suggestion for this feature. If it works, it should > print: > {code} > Hello ${city} from Hamburg > {code} > {code} > // untrusted user input > String userInputName = "${city}"; > String userInputCity = "Hamburg"; > Map valueMap = new HashMap<>(); > valueMap.put("name", userInputName); > valueMap.put("city", userInputCity); > String source = "Hello ${name} from ${city}"; > StrSubstitutor strSubstitutor = new StrSubstitutor(valueMap); > // strSubstitutor.setEnableSubstitutionInValues(false); > System.out.println(strSubstitutor.replace(source)); > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)
[jira] [Updated] (CSV-213) CSVParser#terator()#hasNext() fails
[ https://issues.apache.org/jira/browse/CSV-213?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Lukas Vasek updated CSV-213: Attachment: 999751170.patch.csv > CSVParser#terator()#hasNext() fails > --- > > Key: CSV-213 > URL: https://issues.apache.org/jira/browse/CSV-213 > Project: Commons CSV > Issue Type: Bug > Components: Parser >Affects Versions: 1.4 > Environment: linux/osx >Reporter: Lukas Vasek >Priority: Blocker > Attachments: 999751170.patch.csv > > > Hello, > with class sample below and attached fail the program fails. Problem is that > iterator wrongly computes the records. If hasNext is true then next record > should be fetched. > + wouldn't it be better to provide currentRecord also? > {code:java} > public class Test { > private static final CSVFormat csvFormat = > CSVFormat.DEFAULT > .withDelimiter(';') > .withFirstRecordAsHeader() > .withRecordSeparator('\n') > .withQuoteMode(QuoteMode.ALL); > private static Optional createEndChannel(File csvFile) { > try (Reader reader = new InputStreamReader(new > FileInputStream(csvFile), StandardCharsets.UTF_8); > CSVParser parser = new CSVParser(reader, csvFormat)) { > if (parser.iterator().hasNext()) { > System.out.println(parser.getCurrentLineNumber()); > System.out.println(parser.getRecordNumber()); > // get only first record we don't need other's > CSVRecord firstRecord = parser.iterator().next(); // this > fails > return Optional.of(null); > } > } catch (IOException e) { > throw new RuntimeException("Error while adding end channel to > csv", e); > } > return Optional.empty(); > } > public static void main(String[] args) { > createEndChannel(new File("/tmp/999751170.patch.csv")); > //createEndChannel(new File("/tmp/129441.csv")); > } > } > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)
[jira] [Created] (CSV-213) CSVParser#terator()#hasNext() fails
Lukas Vasek created CSV-213: --- Summary: CSVParser#terator()#hasNext() fails Key: CSV-213 URL: https://issues.apache.org/jira/browse/CSV-213 Project: Commons CSV Issue Type: Bug Components: Parser Affects Versions: 1.4 Environment: linux/osx Reporter: Lukas Vasek Priority: Blocker Hello, with class sample below and attached fail the program fails. Problem is that iterator wrongly computes the records. If hasNext is true then next record should be fetched. + wouldn't it be better to provide currentRecord also? {code:java} public class Test { private static final CSVFormat csvFormat = CSVFormat.DEFAULT .withDelimiter(';') .withFirstRecordAsHeader() .withRecordSeparator('\n') .withQuoteMode(QuoteMode.ALL); private static Optional createEndChannel(File csvFile) { try (Reader reader = new InputStreamReader(new FileInputStream(csvFile), StandardCharsets.UTF_8); CSVParser parser = new CSVParser(reader, csvFormat)) { if (parser.iterator().hasNext()) { System.out.println(parser.getCurrentLineNumber()); System.out.println(parser.getRecordNumber()); // get only first record we don't need other's CSVRecord firstRecord = parser.iterator().next(); // this fails return Optional.of(null); } } catch (IOException e) { throw new RuntimeException("Error while adding end channel to csv", e); } return Optional.empty(); } public static void main(String[] args) { createEndChannel(new File("/tmp/999751170.patch.csv")); //createEndChannel(new File("/tmp/129441.csv")); } } {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)