diff --git a/check/checkdata/schema/schema.go b/check/checkdata/schema/schema.go index eb3d9c2dd..a0b9855bd 100644 --- a/check/checkdata/schema/schema.go +++ b/check/checkdata/schema/schema.go @@ -75,7 +75,15 @@ func ValidationErrorMatch(typeQuery string, fieldQuery string, descriptionQueryR // pathURI returns the URI representation of the path argument. func pathURI(path *paths.Path) string { - uriFriendlyPath := filepath.ToSlash(path.String()) + absolutePath, err := path.Abs() + if err != nil { + panic(err.Error()) + } + uriFriendlyPath := filepath.ToSlash(absolutePath.String()) + // In order to be valid, the path in the URI must start with `/`, but Windows paths do not. + if uriFriendlyPath[0] != '/' { + uriFriendlyPath = "/" + uriFriendlyPath + } pathURI := url.URL{ Scheme: "file", Path: uriFriendlyPath, diff --git a/check/checkdata/schema/schema_test.go b/check/checkdata/schema/schema_test.go new file mode 100644 index 000000000..578813084 --- /dev/null +++ b/check/checkdata/schema/schema_test.go @@ -0,0 +1,18 @@ +package schema + +import ( + "runtime" + "testing" + + "github.com/arduino/go-paths-helper" + "github.com/stretchr/testify/require" +) + +func TestPathURI(t *testing.T) { + switch runtime.GOOS { + case "windows": + require.Equal(t, "file:///c:/foo%20bar", pathURI(paths.New("c:/foo bar"))) + default: + require.Equal(t, "file:///foo%20bar", pathURI(paths.New("/foo bar"))) + } +} diff --git a/go.mod b/go.mod index 6d7d5cfd8..d5abf5daf 100644 --- a/go.mod +++ b/go.mod @@ -7,5 +7,6 @@ require ( github.com/arduino/go-paths-helper v1.3.2 github.com/arduino/go-properties-orderedmap v1.4.0 github.com/sirupsen/logrus v1.6.0 + github.com/stretchr/testify v1.6.1 github.com/xeipuuv/gojsonschema v1.2.0 )