lib/briard/doi_utils.rb in briard-2.7.0 vs lib/briard/doi_utils.rb in briard-2.7.1

- old
+ new

@@ -10,14 +10,14 @@ def validate_funder_doi(doi) doi = Array(%r{\A(?:(http|https):/(/)?(dx\.)?(doi\.org|handle\.stage\.datacite\.org|handle\.test\.datacite\.org)/)?(doi:)?(10\.13039/)?([1-9]\d+)\z}.match(doi)).last # remove non-printing whitespace and downcase - if doi.present? - doi.delete("\u200B").downcase - "https://doi.org/10.13039/#{doi}" - end + return unless doi.present? + + doi.delete("\u200B").downcase + "https://doi.org/10.13039/#{doi}" end def validate_prefix(doi) Array(%r{\A(?:(http|https):/(/)?(dx\.)?(doi\.org|handle\.stage\.datacite\.org|handle\.test\.datacite\.org)/)?(doi:)?(10\.\d{4,5}).*\z}.match(doi)).last end @@ -39,13 +39,15 @@ # turn DOI into URL, escape unsafe characters doi_resolver(doi, options) + Addressable::URI.encode(doi_str) end def doi_from_url(url) - if %r{\A(?:(http|https)://(dx\.)?(doi\.org|handle\.stage\.datacite\.org|handle\.test\.datacite\.org)/)?(doi:)?(10\.\d{4,5}/.+)\z}.match?(url) - uri = Addressable::URI.parse(url) - uri.path.gsub(%r{^/}, '').downcase + unless %r{\A(?:(http|https)://(dx\.)?(doi\.org|handle\.stage\.datacite\.org|handle\.test\.datacite\.org)/)?(doi:)?(10\.\d{4,5}/.+)\z}.match?(url) + return end + + uri = Addressable::URI.parse(url) + uri.path.gsub(%r{^/}, '').downcase end def doi_as_url(doi) "https://doi.org/#{doi}" if doi.present? end