summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorDaniel Lavrushin <[email protected]>2026-01-19 22:23:49 +0100
committerGitHub <[email protected]>2026-01-20 05:23:49 +0800
commit2ada75048219a9d8c337439d0c91e1af45b99ed3 (patch)
tree32d72fdcb43f53408c8b9d6a15c0b86e45c24bdc /plugin
parentad842f2ccd5ede867560ea7171c8aa334a3b1742 (diff)
Fix: processing JSON path (#289)202601192124
Co-authored-by: Loyalsoldier <[email protected]>
Diffstat (limited to 'plugin')
-rw-r--r--plugin/plaintext/common_in.go30
1 files changed, 28 insertions, 2 deletions
diff --git a/plugin/plaintext/common_in.go b/plugin/plaintext/common_in.go
index cc7728b1..f8253519 100644
--- a/plugin/plaintext/common_in.go
+++ b/plugin/plaintext/common_in.go
@@ -209,11 +209,37 @@ func (t *TextIn) scanFileForJSONIn(reader io.Reader, entry *lib.Entry) error {
path = strings.TrimSpace(path)
result := gjson.GetBytes(data, path)
- for _, cidr := range result.Array() {
- if err := entry.AddPrefix(cidr.String()); err != nil {
+ if err := t.processJSONResult(result, entry); err != nil {
+ return fmt.Errorf("❌ [type %s | action %s] failed to process JSON: %v", t.Type, t.Action, err)
+ }
+ }
+
+ return nil
+}
+
+func (t *TextIn) processJSONResult(result gjson.Result, entry *lib.Entry) error {
+ switch {
+ case !result.Exists():
+ return fmt.Errorf("invaild IP address or CIDR (value not exist), please check your specified JSON path or JSON source")
+
+ case result.Type == gjson.String:
+ cidr := strings.TrimSpace(result.String())
+ if cidr == "" {
+ return fmt.Errorf("empty string, please check your specified JSON path or JSON source")
+ }
+ if err := entry.AddPrefix(cidr); err != nil {
+ return err
+ }
+
+ case result.IsArray():
+ for _, item := range result.Array() {
+ if err := t.processJSONResult(item, entry); err != nil {
return err
}
}
+
+ default:
+ return fmt.Errorf("invaild IP address or CIDR, please check your specified JSON path or JSON source")
}
return nil