Skip to content

Commit b74fff7

Browse files
authored
Fixed bug in removing trailing delimiter
The existing code strips all trailing delimiters which is incorrect, it should only remove the final delimiter. The problem occurs when the last column is empty. Say you export three fields, first name, last name & email (where email is null). Expected output would be "John;Doe;" but instead you get "John;Doe" which is problematic.
1 parent 3fe0a7b commit b74fff7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/WebApiContrib.Core.Formatter.Csv/CsvOutputFormatter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public async override Task WriteResponseBodyAsync(OutputFormatterWriteContext co
149149
}
150150
}
151151

152-
await streamWriter.WriteLineAsync(valueLine.TrimEnd(_options.CsvDelimiter.ToCharArray()));
152+
await streamWriter.WriteLineAsync(valueLine.Remove(valueLine.Length - _options.CsvDelimiter.Length));
153153
}
154154

155155
await streamWriter.FlushAsync();

0 commit comments

Comments
 (0)