Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Daqifi.Core.Tests/Device/SdCard/SdCardOperationsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,33 @@ public async Task GetSdCardFilesAsync_ParsesResponseCorrectly()
Assert.Null(files[1].CreatedDate);
}

[Fact]
public async Task GetSdCardFilesAsync_FilenamesStartingWithErrorAreNotMisclassified()
{
// Regression for #190: IsNonResultLine's prior bare "ERROR"
// prefix check false-positived on legit SD filenames whose
// basename starts with "error" (e.g. "error_log.csv"). The
// permissive classifier dropped them from the parsed file
// list. Tightened to require ERROR followed by `:`/` `/`!`/
// tab so ordinary filenames pass through.
var device = new TestableSdCardStreamingDevice("TestDevice");
device.CannedTextResponse = new List<string>
{
"Daqifi/error_log.csv",
"Daqifi/Errors_summary.bin",
"Daqifi/normal.bin",
};
device.Connect();

var files = await device.GetSdCardFilesAsync();

var names = files.Select(f => f.FileName).ToList();
Assert.Contains("error_log.csv", names);
Assert.Contains("Errors_summary.bin", names);
Assert.Contains("normal.bin", names);
Assert.Equal(3, files.Count);
}

[Fact]
public async Task GetSdCardFilesAsync_RestoresLanInterface()
{
Expand Down
23 changes: 20 additions & 3 deletions src/Daqifi.Core/Device/DaqifiStreamingDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -749,12 +749,29 @@ private static bool IsScpiErrorLine(string line)
// Permissive: any line that looks like a device error or status message,
// including firmware text such as "Error !! ...". Used to recognize that
// the parser would yield no result, without polluting LastScpiError with
// non-SCPI text.
// non-SCPI text. Closes #190 — bare "ERROR" prefix false-positives on
// legit SD filenames that happen to start with "error" (e.g.
// "error_log.csv"), which would mask the file from GetSdCardFilesAsync's
// returned list. Tightened to require ERROR followed by ":", " " (firmware
// pattern "Error !!"), or "*" (the "**ERROR" SCPI marker, also matched by
// IsScpiErrorLine).
private static bool IsNonResultLine(string line)
{
var trimmed = line.TrimStart();
return trimmed.StartsWith("**ERROR", StringComparison.OrdinalIgnoreCase)
|| trimmed.StartsWith("ERROR", StringComparison.OrdinalIgnoreCase);
if (trimmed.StartsWith("**ERROR", StringComparison.OrdinalIgnoreCase))
return true;
// Must be followed by a non-letter so plain filenames like
// "error_log.csv" (which TrimStart leaves intact) don't match.
if (trimmed.Length >= 5
&& trimmed.StartsWith("ERROR", StringComparison.OrdinalIgnoreCase))
{
if (trimmed.Length == 5)
return true;
var next = trimmed[5];
if (next == ':' || next == ' ' || next == '!' || next == '\t')
return true;
}
return false;
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Outdated
}

/// <summary>
Expand Down
Loading