Skip to content

Commit 273e738

Browse files
authored
Only allow full semantic versions. (#56)
Also require tags to have a 'v' in front.
1 parent 9637186 commit 273e738

File tree

15 files changed

+63
-95
lines changed

15 files changed

+63
-95
lines changed

go.mod

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/toitlang/tpkg
33
go 1.20
44

55
require (
6+
github.com/Masterminds/semver/v3 v3.2.1
67
github.com/alessio/shellescape v1.4.1
78
github.com/alexflint/go-filemutex v1.1.0
89
github.com/go-git/go-git/v5 v5.8.1
@@ -30,14 +31,11 @@ require (
3031
github.com/go-git/go-billy/v5 v5.4.1 // indirect
3132
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3233
github.com/golang/protobuf v1.3.2 // indirect
33-
github.com/google/go-cmp v0.5.9 // indirect
3434
github.com/hashicorp/hcl v1.0.0 // indirect
35-
github.com/imdario/mergo v0.3.12 // indirect
3635
github.com/inconshreveable/mousetrap v1.0.0 // indirect
3736
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
3837
github.com/kevinburke/ssh_config v1.2.0 // indirect
3938
github.com/magiconair/properties v1.8.1 // indirect
40-
github.com/mitchellh/go-homedir v1.1.0 // indirect
4139
github.com/mitchellh/mapstructure v1.1.2 // indirect
4240
github.com/pelletier/go-toml v1.2.0 // indirect
4341
github.com/pjbgf/sha1cd v0.3.0 // indirect
@@ -57,7 +55,6 @@ require (
5755
golang.org/x/sys v0.10.0 // indirect
5856
golang.org/x/text v0.11.0 // indirect
5957
golang.org/x/tools v0.6.0 // indirect
60-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
6158
google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a // indirect
6259
gopkg.in/ini.v1 v1.51.0 // indirect
6360
gopkg.in/warnings.v0 v0.1.2 // indirect

go.sum

Lines changed: 8 additions & 64 deletions
Large diffs are not rendered by default.

pkg/tpkg/desc.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"sort"
2525
"strings"
2626

27+
"github.com/Masterminds/semver/v3"
2728
"github.com/hashicorp/go-version"
2829
"gopkg.in/yaml.v2"
2930
)
@@ -385,8 +386,12 @@ func ScrapeDescriptionGit(ctx context.Context, url string, v string, allowsLocal
385386
}
386387

387388
originalVersion := v
388-
v = strings.TrimPrefix(v, "v")
389-
_, err := version.NewVersion(v)
389+
if !strings.HasPrefix(v, "v") {
390+
return nil, ui.ReportError("Invalid version: '%s', not starting with 'v'", originalVersion)
391+
}
392+
v = v[1:]
393+
// Check that it is a valid semantic version.
394+
_, err := semver.StrictNewVersion(v)
390395
if err != nil {
391396
return nil, ui.ReportError("Invalid version: '%s'", originalVersion)
392397
}

tests/assets/pkg/DeepPackage/gold/test.gold

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
pkg registry add --local deep <TEST>/nested_registry
22
Exit Code: 0
33
===================
4-
pkg describe --out-dir=<TEST>/nested_registry github.com/toitware/test-pkg.git/foo 1.0.0
4+
pkg describe --out-dir=<TEST>/nested_registry github.com/toitware/test-pkg.git/foo v1.0.0
55
Exit Code: 0
66
Info: Wrote '<TEST>/nested_registry/packages/github.com/toitware/test-pkg.git/foo/1.0.0/desc.yaml'
77
===================
8-
pkg describe --out-dir=<TEST>/nested_registry github.com/toitware/test-pkg.git/foo 2.3.0
8+
pkg describe --out-dir=<TEST>/nested_registry github.com/toitware/test-pkg.git/foo v2.3.0
99
Exit Code: 0
1010
Info: Wrote '<TEST>/nested_registry/packages/github.com/toitware/test-pkg.git/foo/2.3.0/desc.yaml'
1111
===================
12-
pkg describe --out-dir=<TEST>/nested_registry github.com/toitware/test-pkg.git/bar/gee 1.0.1
12+
pkg describe --out-dir=<TEST>/nested_registry github.com/toitware/test-pkg.git/bar/gee v1.0.1
1313
Exit Code: 0
1414
Info: Wrote '<TEST>/nested_registry/packages/github.com/toitware/test-pkg.git/bar/gee/1.0.1/desc.yaml'
1515
===================
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pkg describe https://github.com/toitware/toit-ignore 1.0
2+
Exit Code: 1
3+
Error: Invalid version: '1.0', not starting with 'v'
4+
===================
5+
pkg describe https://github.com/toitware/toit-ignore v1.0
6+
Exit Code: 1
7+
Error: Invalid version: 'v1.0'
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
pkg describe https://github.com/toitware/toit-morse 1.0.0
2+
Exit Code: 1
3+
Error: Invalid version: '1.0.0', not starting with 'v'
4+
===================
15
pkg describe https://github.com/toitware/toit-morse bad-version
26
Exit Code: 1
3-
Error: Invalid version: 'bad-version'
7+
Error: Invalid version: 'bad-version', not starting with 'v'
8+
===================
9+
pkg describe https://github.com/toitware/toit-morse vbad-version
10+
Exit Code: 1
11+
Error: Invalid version: 'vbad-version'

tests/assets/pkg/ScrapeGit/gold/deep.gold

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pkg describe https://github.com/toitware/test-pkg.git/foo 1.0.0
1+
pkg describe https://github.com/toitware/test-pkg.git/foo v1.0.0
22
Exit Code: 0
33
foo:
44
description: nested package foo

tests/assets/pkg/ScrapeGit/gold/https_morse.gold

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pkg describe https://github.com/toitware/toit-morse 1.0.6
1+
pkg describe https://github.com/toitware/toit-morse v1.0.6
22
Exit Code: 0
33
morse:
44
description: Functions for International (ITU) Morse code.

tests/assets/pkg/ScrapeGit/gold/https_morse_dot_git.gold

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pkg describe https://github.com/toitware/toit-morse.git 1.0.6
1+
pkg describe https://github.com/toitware/toit-morse.git v1.0.6
22
Exit Code: 0
33
morse:
44
description: Functions for International (ITU) Morse code.

tests/assets/pkg/ScrapeGit/gold/local_dep.gold

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
pkg describe https://github.com/toitware/test-pkg.git/local_dep 1.0.0
1+
pkg describe https://github.com/toitware/test-pkg.git/local_dep v1.0.0
22
Exit Code: 1
33
Error: Dependency to local path: 'some/path'
44
===================
5-
pkg describe --allow-local-deps https://github.com/toitware/test-pkg.git/local_dep 1.0.0
5+
pkg describe --allow-local-deps https://github.com/toitware/test-pkg.git/local_dep v1.0.0
66
Exit Code: 0
77
local_dep:
88
description: nested package local_dep with local dependency

0 commit comments

Comments
 (0)