@@ -876,6 +876,8 @@ func setNestedMap(m map[string]interface{}, path string, value interface{}) (map
876876 nested = map [string ]interface {}{
877877 keys [i ]: nested ,
878878 }
879+ } else {
880+ log .Printf ("[DEBUG] NOT schemaless_list" )
879881 }
880882 } else {
881883 nested = map [string ]interface {}{
@@ -944,22 +946,20 @@ func handleMultiListItems(translatedInput []interface{}, parentKey string, parse
944946 translatedInput = handleMultiListItems (translatedInput , newKey , val , listDepth , childIndex )
945947
946948 } else if val , ok := v .([]interface {}); ok {
947- log .Printf ("\n \n PARENT LIST: %s\n \n " , childKey )
948-
949949 newKey := fmt .Sprintf ("%s.%s.#" , parentKey , childKey )
950- _ = newKey
951- _ = val
952950
953951 // FIXME: Re-enable this for sub-lists
954952 for cnt , subItem := range val {
955- translatedInput = handleMultiListItems (translatedInput , newKey , subItem .(map [string ]interface {}), listDepth + 1 , cnt )
953+ if parsedSubitem , ok := subItem .(map [string ]interface {}); ok {
954+ translatedInput = handleMultiListItems (translatedInput , newKey , parsedSubitem , listDepth + 1 , cnt )
955+ } else {
956+ log .Printf ("[ERROR] Schemaless: List item '%s' in key '%s' is not a map[string]interface{}, but %T. This is not handled yet." , childKey , parentKey , subItem )
957+ }
956958 }
957959
958960
959961 } else if val , ok := v .(string ); ok {
960962 if strings .Contains (val , "schemaless_list[" ) {
961- log .Printf ("CONTAINS: %#v!!\n \n \n " , val )
962-
963963 //if val == "schemaless_list[]" || val == "schemaless_list" {
964964 //}
965965
@@ -977,7 +977,7 @@ func handleMultiListItems(translatedInput []interface{}, parentKey string, parse
977977 }
978978
979979 oldParentKey := parentKey
980- newParentKey := ""
980+ newParentKey := parentKey
981981 modificationList := translatedInput
982982 if listDepth > 0 {
983983 parentKeySplit := strings .Split (parentKey , "." )
@@ -999,7 +999,6 @@ func handleMultiListItems(translatedInput []interface{}, parentKey string, parse
999999 }
10001000
10011001 newParentKey = strings .Join (newKeySplit , "." )
1002- parentKey = newParentKey
10031002 modificationList = []interface {}{
10041003 parsedValues ,
10051004 }
@@ -1016,45 +1015,54 @@ func handleMultiListItems(translatedInput []interface{}, parentKey string, parse
10161015
10171016
10181017 // Update the translatedInput with the new value
1019- newKey := fmt .Sprintf ("%s.%s" , parentKey , childKey )
1018+ newKey := fmt .Sprintf ("%s.%s" , newParentKey , childKey )
10201019 newKey = strings .SplitN (newKey , "." , 2 )[1 ]
10211020
10221021 //cntItem := modificationList[cnt].(map[string]interface{})
1022+ //if len(listValue) > 10 {
1023+ // log.Printf("Setting value %#v for key '%s' in modificationList[%d]", listValue, newKey, cnt)
1024+ //}
10231025
1024- log .Printf ("VALUE: %#v" , listValue )
1025- //modificationList[cnt], found = setNestedMap(cntItem, newKey, listValue)
10261026 modificationList [cnt ], found = setNestedMap (modificationList [cnt ].(map [string ]interface {}), newKey , listValue )
10271027 if ! found {
1028- log .Printf ("[ERROR] Schemaless: Could not set nested map for key '%s' with value '%s'. Count: %#v" , newKey , listValue , cnt )
1028+ if debug {
1029+ log .Printf ("[ERROR] Schemaless: Could not set nested map for key '%s' with value '%s'. Count: %#v" , newKey , listValue , cnt )
1030+ }
10291031 }
10301032 }
10311033
10321034 if listDepth > 0 {
10331035 // Updates the child & here
10341036 // This shit also needs recursion.. gahh
10351037
1036- log .Printf ("Updating CHILD INDEX %#v" , childIndex )
1038+ if debug {
1039+ log .Printf ("Updating CHILD LOOP INDEX %#v" , childIndex )
1040+ }
1041+
10371042 parsedValues = modificationList [childIndex ].(map [string ]interface {})
10381043
10391044 // And it needs to automatically find the right one
10401045 if strings .HasPrefix (oldParentKey , "." ) {
10411046 oldParentKey = strings .Trim (oldParentKey , "." )
10421047 }
10431048 //oldParentKey = fmt.Sprintf("cve.cvssloop.#")
1044- log .Printf ("KEY TO PUT IN: %#v. Value: %s" , oldParentKey , modificationList )
1049+
1050+ if debug {
1051+ log .Printf ("[DEBUG] Potential LOOP problem: KEY TO PUT IN: %#v. Value: %s" , oldParentKey , modificationList )
1052+ }
1053+
10451054 for inputKey , _ := range translatedInput {
10461055 translatedInput [inputKey ], found = setNestedMap (translatedInput [inputKey ].(map [string ]interface {}), oldParentKey , modificationList )
10471056 if found {
1048- log .Printf ("\n \n \n BREAKING - FOUND WHERE TO PUT IT!" )
10491057 break
10501058 }
10511059 }
10521060 } else {
10531061 translatedInput = modificationList
10541062 }
10551063
1056- marshalled , _ := json .MarshalIndent (translatedInput , "" , "\t " )
1057- log .Printf ("MARSHALLED (%d): %s." , listDepth , string (marshalled ))
1064+ // marshalled, _ := json.MarshalIndent(translatedInput, "", "\t")
1065+ // log.Printf("MARSHALLED (%d): %s.", listDepth, string(marshalled))
10581066
10591067 //translatedInput = modificationList
10601068
@@ -1172,9 +1180,9 @@ func runJsonTranslation(ctx context.Context, inputValue []byte, translation map[
11721180
11731181 translatedInput [translationKey ] = newOutput
11741182 } else {
1175- if debug {
1176- log .Printf ("[ERROR] Schemaless DEBUG issue: No output found for key '%s' after translation. This COULD be working as intended." , translationKey )
1177- }
1183+ // if debug {
1184+ // log.Printf("[ERROR] Schemaless DEBUG issue: No output found for key '%s' after translation. This COULD be working as intended.", translationKey)
1185+ // }
11781186
11791187 translatedInput [translationKey ] = translationValue
11801188 }
0 commit comments