Skip to content

Commit

Permalink
fix prefix parsing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mfenner committed Apr 26, 2024
1 parent f08dc20 commit 5e5a926
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
},
}

Expand Down
4 changes: 2 additions & 2 deletions doiutils/doiutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions doiutils/doiutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5e5a926

Please sign in to comment.