Skip to content

Commit

Permalink
nokia_sros: handle CRLF and tabs in partialCfg (#2382)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcpvdm authored Jan 10, 2025
1 parent 2211b9b commit dd321ab
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions nodes/vr_sros/vr-sros.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,10 @@ func (s *vrSROS) applyPartialConfig(ctx context.Context, addr, platformName,
return err
}

configContentStr := string(configContent)

// check file contains content, otherwise exit early
if strings.TrimSpace(string(configContent)) == "" {
if strings.TrimSpace(configContentStr) == "" {
return nil
}

Expand Down Expand Up @@ -315,8 +317,16 @@ func (s *vrSROS) applyPartialConfig(ctx context.Context, addr, platformName,
}
}
}
// converting byte slice to newline delimited string slice
cfgs := strings.Split(string(configContent), "\n")

// Normalize character sequences to avoid interaction issues with CLI
replacer := strings.NewReplacer(
"\r\n", "\n", // replace EOL CRLF with LF
"\t", " ", // replace tabs with 4 spaces
)
configContentStr = replacer.Replace(configContentStr)

// converting string to newline delimited string slice
cfgs := strings.Split(configContentStr, "\n")

// config snippets should not have commit command, so we need to commit manually
// and quit from the config mode
Expand Down

0 comments on commit dd321ab

Please sign in to comment.