opened
yaauie
username_0
REE: newline at end of conf file fragment corrupts next conf file
issue
created
yaauie
username_0
comment
created
andsel
username_1
We could count the number of newlines character, something like:
```java
"Hello\nWorld\n\n\n\n".chars().filter(x -> x == '\n').count();
```
but if we have `\r` or `\r\n` we could think to use the Matcher to count:

```java
Matcher m = Pattern.compile("\r\n|\r|\n").matcher("Hello\nWorld\n\n\n");
int linesCount = 0;
while (m.find()) {
    linesCount++;
}
```
comment
created
yaauie
username_0
I created a patch that used `String#split(String, int)` with `-1` for the second argument, which caused it to include an empty entry when there was a trailing newline, but on second thought, it is _weird_ for `SourceWithMetadata#getLinesCount()` to return `2` for the input `input { stdin {} }\n` because the newline is usually considered to be a part of the line.

Instead I am trying a fix that addresses the _concatenation_ of source files for our internal representation that joins sources on newline whether or not they already had a trailing newline, by pre-normalizing to chomp trailing newlines before we perform the concatenation.
comment