From 15cf7d90ee21d4a75f5d5e57253d4731249503a1 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 9 Oct 2024 12:19:58 +0200 Subject: [PATCH] Write relative paths only if path is inside prefix --- internal/arduino/libraries/libraries.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/arduino/libraries/libraries.go b/internal/arduino/libraries/libraries.go index 025443488c3..7c2cb39fdca 100644 --- a/internal/arduino/libraries/libraries.go +++ b/internal/arduino/libraries/libraries.go @@ -20,6 +20,7 @@ import ( "errors" "fmt" "io" + "path/filepath" "github.com/arduino/arduino-cli/internal/arduino/cores" "github.com/arduino/arduino-cli/internal/arduino/globals" @@ -148,6 +149,10 @@ func (library *Library) MarshalBinary(out io.Writer, prefix *paths.Path) error { writePath := func(in *paths.Path) error { if in == nil { return writeString("") + } else if inside, err := in.IsInsideDir(prefix); err != nil { + return err + } else if !inside { + return writeString(in.String()) } else if p, err := in.RelFrom(prefix); err != nil { return err } else { @@ -308,6 +313,8 @@ func (library *Library) UnmarshalBinary(in io.Reader, prefix *paths.Path) error return nil, err } else if p == "" { return nil, nil + } else if filepath.IsAbs(p) { + return paths.New(p), nil } else { return prefix.Join(p), nil }