Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions ygot/pathstrings.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"bytes"
"errors"
"fmt"
stdpath "path"
"sort"
"strings"

Expand All @@ -43,7 +42,7 @@ const (
// representing the path. Path is always treated as absolute.
func PathToString(path *gnmipb.Path) (string, error) {
s, err := PathToStrings(path)
return "/" + stdpath.Join(s...), err
return "/" + strings.Join(s, "/"), err
}

// PathToSchemaPath returns the supplied Path as its corresponding schema path.
Expand All @@ -66,7 +65,7 @@ func PathToSchemaPath(path *gnmipb.Path) (string, error) {
sp = append(sp, elem)
}
s, err := elementsToString(sp)
return "/" + stdpath.Join(s...), err
return "/" + strings.Join(s, "/"), err
}

var p []string
Expand All @@ -76,7 +75,7 @@ func PathToSchemaPath(path *gnmipb.Path) (string, error) {
}
p = append(p, e.Name)
}
return "/" + stdpath.Join(p...), nil
return "/" + strings.Join(p, "/"), nil
}

// PathToStrings takes a gNMI Path and provides its string representation. For example,
Expand Down
14 changes: 14 additions & 0 deletions ygot/pathstrings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ func TestPathToString(t *testing.T) {
}},
},
want: "/one/two/three", // should have the element type, not elem.
}, {
name: "key value with repeated slash is preserved",
in: &gnmipb.Path{Elem: []*gnmipb.PathElem{
{Name: "a", Key: map[string]string{"k": "x//y"}},
{Name: "b"},
}},
want: "/a[k=x//y]/b",
}, {
name: "key value with dot segments is preserved",
in: &gnmipb.Path{Elem: []*gnmipb.PathElem{
{Name: "a", Key: map[string]string{"k": "p/../q"}},
{Name: "b"},
}},
want: "/a[k=p/../q]/b",
}}

for _, tt := range tests {
Expand Down
Loading