-
Notifications
You must be signed in to change notification settings - Fork 64
Description
trim() calculates the "minimum indent" of every line after the first, and then removes that number of characters from the beginning of every line after the first. I encountered this while working on the related #162.
min_indent is calculated by a routine that ignores indentation (spaces and tabs) on blank lines - lines containing only indentation. Consequently, the newline that terminates these lines can get trimmed, which causes the following line to include spurious leading whitespace.
Failing example:
library(glue)
library(testthat)
expect_identical(
trim("
\ta
\tb
\t
\tc"),
"a\nb\n\nc"
)In the character vector passed to trim(), the penultimate line contains only indentation (6 spaces followed by a tab).
When trim() is copying parts of the old string to a new one, it skips over the newline that delimits the penultimate and last lines, and the whitespace from the penultimate line is included in the last line.