From dd321ab7ad0c4b00b0809dc8b33870ba7e113f0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Machado?= <63718541+jcpvdm@users.noreply.github.com> Date: Fri, 10 Jan 2025 11:38:10 +0000 Subject: [PATCH] nokia_sros: handle CRLF and tabs in partialCfg (#2382) --- nodes/vr_sros/vr-sros.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/nodes/vr_sros/vr-sros.go b/nodes/vr_sros/vr-sros.go index 255846150..c838db836 100644 --- a/nodes/vr_sros/vr-sros.go +++ b/nodes/vr_sros/vr-sros.go @@ -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 } @@ -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