Skip to content

Commit

Permalink
Write relative paths only if path is inside prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Oct 28, 2024
1 parent a1cc424 commit 15cf7d9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/arduino/libraries/libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 15cf7d9

Please sign in to comment.