Skip to content

[release-1.17] Use strings.Fields for whitespace splitting to fix issues with strings.Split in case of multiple consecutive spaces #2008

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

Merged
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
4 changes: 2 additions & 2 deletions pkg/gce-pd-csi-driver/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func fetchRAIDedLocalSsdPath() (string, error) {
return "", fmt.Errorf("Error getting RAIDed device path for Data Cache %v, output:%v", err, string(info))
}
infoString := strings.TrimSpace(string(info))
infoSlice := strings.Split(infoString, " ")
infoSlice := strings.Fields(infoString)

// We want to get the second element in the array (sample: ARRAY /dev/md126 metadata=1.2 name=csi-driver-data-cache UUID=*),
// which is the path to the RAIDed device
Expand Down Expand Up @@ -357,7 +357,7 @@ func FetchAllLssds() ([]string, error) {
for _, ssd := range infoList {
ssd = strings.TrimSpace(ssd)
if strings.HasPrefix(ssd, "/dev/nvme") {
ssdDetails := strings.Split(ssd, " ")
ssdDetails := strings.Fields(ssd)
lssd := re.MatchString(ssdDetails[1])
if lssd {
diskList = append(diskList, strings.TrimSpace(ssdDetails[0]))
Expand Down