diff --git a/cmd/version.go b/cmd/version.go index c67afe3..7b8f431 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -15,7 +15,7 @@ var versionCmd = &cobra.Command{ Short: "Print the version number of commonmeta", Long: `All software has versions. This is commonmeta's`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("Commonmeta v0.2.1 -- HEAD") + fmt.Println("Commonmeta v0.2.2 -- HEAD") }, } diff --git a/doiutils/doiutils.go b/doiutils/doiutils.go index 45e07e3..14cf7bb 100644 --- a/doiutils/doiutils.go +++ b/doiutils/doiutils.go @@ -51,7 +51,7 @@ func ValidateDOI(doi string) (string, bool) { // ValidatePrefix validates a DOI prefix for a given DOI func ValidatePrefix(doi string) (string, bool) { - r, err := regexp.Compile(`^(?:(http|https):/(/)?(dx\.)?(doi\.org|handle\.stage\.datacite\.org|handle\.test\.datacite\.org)/)?(doi:)?(10\.\d{4,5})/.+$`) + r, err := regexp.Compile(`^(?:(http|https):/(/)?(dx\.)?(doi\.org|handle\.stage\.datacite\.org|handle\.test\.datacite\.org)/)?(doi:)?(10\.\d{4,5})`) if err != nil { log.Printf("Error compiling regex: %v", err) return "", false @@ -75,7 +75,7 @@ func DOIResolver(doi string, sandbox bool) string { return "https://doi.org/" } -// GetDOIRA returns the DOI registration agency for a given DOI +// GetDOIRA returns the DOI registration agency for a given DOI or prefix func GetDOIRA(doi string) (string, bool) { prefix, ok := ValidatePrefix(doi) if !ok { diff --git a/doiutils/doiutils_test.go b/doiutils/doiutils_test.go index a5e9109..3240d58 100644 --- a/doiutils/doiutils_test.go +++ b/doiutils/doiutils_test.go @@ -37,14 +37,14 @@ func TestValidatePrefix(t *testing.T) { testCases := []testCase{ {input: "10.7554/elife.01567", want: "10.7554"}, {input: "https://doi.org/10.7554/elife.01567", want: "10.7554"}, - {input: "https://doi.org/10.7554", want: ""}, - {input: "10.7554", want: ""}, + {input: "https://doi.org/10.7554", want: "10.7554"}, + {input: "10.7554", want: "10.7554"}, {input: "", want: ""}, } for _, tc := range testCases { got, ok := doiutils.ValidatePrefix(tc.input) if tc.want != got { - t.Errorf("Validate DOI(%v): want %v, got %v, ok %v", + t.Errorf("Validate Prefix (%v): want %v, got %v, ok %v", tc.input, tc.want, got, ok) } } @@ -82,6 +82,7 @@ func TestGetDOIRA(t *testing.T) { {input: "10.7554/elife.01567", want: "Crossref"}, {input: "https://doi.org/10.5061/dryad.8515", want: "DataCite"}, {input: "10.9999", want: ""}, + {input: "10.7554", want: "Crossref"}, {input: "", want: ""}, } for _, tc := range testCases {