Fixed issue where query only exported to file

This commit is contained in:
Evan Hosinski
2026-04-07 09:37:41 -04:00
parent 5905b3478d
commit f23bd04114
7 changed files with 133 additions and 56 deletions
+17 -13
View File
@@ -163,20 +163,24 @@ func (dwr DataWellsResponse) String() string {
}
func dataWellGreppable(well DataWell) string {
fields := []string{
"name=" + cleanGreppableValue(well.Name),
"date=" + cleanGreppableValue(well.Date),
"records=" + strconv.Itoa(well.Records),
"is_sensitive=" + strconv.FormatBool(well.IsSensitive),
"data=" + cleanGreppableValue(well.Data),
"description=" + cleanGreppableValue(well.Description),
}
return strings.Join(fields, "\t")
var fields []string
fields = appendDataWellGreppableField(fields, "name", well.Name)
fields = appendDataWellGreppableField(fields, "date", well.Date)
fields = appendDataWellGreppableField(fields, "records", strconv.Itoa(well.Records))
fields = appendDataWellGreppableField(fields, "is_sensitive", strconv.FormatBool(well.IsSensitive))
fields = appendDataWellGreppableField(fields, "data", well.Data)
fields = appendDataWellGreppableField(fields, "description", well.Description)
return strings.Join(fields, " ")
}
func cleanGreppableValue(value string) string {
value = strings.ReplaceAll(value, "\r", " ")
value = strings.ReplaceAll(value, "\n", " ")
value = strings.ReplaceAll(value, "\t", " ")
return strings.TrimSpace(value)
return strings.Join(strings.Fields(value), "_")
}
func appendDataWellGreppableField(fields []string, key, value string) []string {
value = cleanGreppableValue(value)
if value == "" {
return fields
}
return append(fields, fmt.Sprintf("%s=%s", key, value))
}
+22
View File
@@ -70,3 +70,25 @@ func TestDataWellsURLDoesNotRequireAPIKey(t *testing.T) {
}
}
}
func TestDataWellGreppableUsesSpaceSeparatedNonEmptyTokens(t *testing.T) {
got := dataWellGreppable(DataWell{
Name: "Example Breach",
Date: "2025-03-01",
Records: 500000,
IsSensitive: true,
Data: "name,email,address",
})
if strings.Contains(got, "\t") {
t.Fatalf("greppable output contains tab: %q", got)
}
if strings.Contains(got, "description=") {
t.Fatalf("greppable output contains empty field: %q", got)
}
for _, want := range []string{"name=Example_Breach", "date=2025-03-01", "records=500000", "is_sensitive=true", "data=name,email,address"} {
if !strings.Contains(got, want) {
t.Fatalf("greppable output = %q, want token %q", got, want)
}
}
}