Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using ExceptionMessagesContainRawData = false the RawRecord data still appears in the exception #2329

Open
markrsalt opened this issue Feb 26, 2025 · 0 comments
Labels

Comments

@markrsalt
Copy link

markrsalt commented Feb 26, 2025

Describe the bug
When reading csv data which causes a TypeConverterException, the Text and RawRecord values are contained in the exception. If ExceptionMessagesContainRawData is set to false, this replaces the Text value but the exception still contains the value of the RawRecord in the property Context.Parser.RawRecord

To Reproduce
`StringBuilder sb = new();
sb.AppendLine("Name,Value");
sb.AppendLine($"Sensitive Name,Sensitive Value");

byte[] byteArray = Encoding.UTF8.GetBytes(sb.ToString());
using MemoryStream memoryStream = new(byteArray);
using StreamReader sr = new(memoryStream);
var reader = new CsvHelper.CsvReader(sr, new CsvConfiguration(System.Globalization.CultureInfo.InvariantCulture) { ExceptionMessagesContainRawData = false });
try
{
reader.Read();
var record = reader.GetRecord();
}
catch(TypeConverterException ex)
{
Console.WriteLine(ex.Context?.Parser?.RawRecord); // RawRecord still contains the sensitive data
}`

Expected behavior
The RawRecord in the exception should contain replacement text when ExceptionMessagesContainRawData = false

@markrsalt markrsalt added the bug label Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant