Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conditional check for split #55

Merged
merged 9 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions gnmi_server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,12 @@ func runGnmiTestGet(t *testing.T, namespace string) {
valTest: true,
wantRetCode: codes.OK,
wantRespVal: []byte(`{"test_field": "test_value"}`),
}, {
desc: "Invalid DBKey of length 1",
pathTarget: stateDBPath,
textPbPath: ``,
valTest: true,
wantRetCode: codes.NotFound,
},

// Happy path
Expand Down
7 changes: 6 additions & 1 deletion sonic_data_client/db_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,9 @@ func populateDbtablePath(prefix, path *gnmipb.Path, pathG2S *map[*gnmipb.Path][]
}
tblPath.dbNamespace = dbNamespace
tblPath.dbName = targetDbName
tblPath.tableName = stringSlice[1]
if len(stringSlice) > 1 {
tblPath.tableName = stringSlice[1]
}
tblPath.delimitor = separator

var mappedKey string
Expand Down Expand Up @@ -717,6 +719,9 @@ func tableData2Msi(tblPath *tablePath, useKey bool, op *string, msi *map[string]
var key string
// Split dbkey string into two parts and second part is key in table
keys := strings.SplitN(dbkey, tblPath.delimitor, 2)
if len(keys) < 2 {
return fmt.Errorf("dbkey: %s, failed split from delimitor %v", dbkey, tblPath.delimitor)
}
key = keys[1]
err = makeJSON_redis(msi, &key, op, fv)
}
Expand Down