Fixed issue where query only exported to file
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user