From cd19093d1d461d6d07a9c57c09a9638eaf025edf Mon Sep 17 00:00:00 2001 From: Immanuel Tikhonov <122638311+immanuwell@users.noreply.github.com> Date: Tue, 12 May 2026 05:44:29 +0400 Subject: [PATCH] fix(openvpn/extract): trim spaces in config lines before parsing (#3327) --- internal/openvpn/extract/extract.go | 2 ++ internal/openvpn/extract/extract_test.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/internal/openvpn/extract/extract.go b/internal/openvpn/extract/extract.go index b5557e46..f2b88302 100644 --- a/internal/openvpn/extract/extract.go +++ b/internal/openvpn/extract/extract.go @@ -53,6 +53,8 @@ func extractDataFromLines(lines []string) ( func extractDataFromLine(line string) ( ip netip.Addr, port uint16, protocol string, err error, ) { + line = strings.TrimSpace(line) + switch { case strings.HasPrefix(line, "proto "): protocol, err = extractProto(line) diff --git a/internal/openvpn/extract/extract_test.go b/internal/openvpn/extract/extract_test.go index 200bfdb8..f5a4362c 100644 --- a/internal/openvpn/extract/extract_test.go +++ b/internal/openvpn/extract/extract_test.go @@ -62,6 +62,14 @@ func Test_extractDataFromLines(t *testing.T) { Protocol: constants.UDP, }, }, + "leading_whitespace": { + lines: []string{" proto tcp", "\tremote 1.2.3.4 443 tcp"}, + connection: models.Connection{ + IP: netip.AddrFrom4([4]byte{1, 2, 3, 4}), + Port: 443, + Protocol: constants.TCP, + }, + }, } for name, testCase := range testCases {