Skip to content

Commit

Permalink
Escape more DOI string characters
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanxu committed Aug 10, 2022
1 parent f4a5f66 commit 97d178b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/lib/doi_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def validate_doi(doi_string)

begin
doi_string.gsub!(/[^a-zA-z0-9:;<>\.\(\)\/\-_]/, "")
escaped_doi_string = doi_string.gsub("<", "%3C").gsub(">", "%3E")
escaped_doi_string = doi_string.gsub("<", "%3C").gsub(">", "%3E").gsub("[", "%5B").gsub("]", "%5D")

doi_url = URI.join("https://doi.org", escaped_doi_string).to_s

Expand Down
5 changes: 5 additions & 0 deletions spec/doi_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@
doi_url = "https://doi.org/10.1002/(sici)1096-9136(199606)13:6%3C536::aid-dia110%3E3.0.co;2-j"
expect(Faraday).to receive(:head).with(doi_url).and_return(OpenStruct.new(status: 301))
subject.validate_doi(doi)

doi = "10.1577/1548-8446(2006)31[590:TCFIE]2.0.CO;2"
doi_url = "https://doi.org/10.1577/1548-8446(2006)31%5B590:TCFIE%5D2.0.CO;2"
expect(Faraday).to receive(:head).with(doi_url).and_return(OpenStruct.new(status: 301))
subject.validate_doi(doi)
end
end

Expand Down

0 comments on commit 97d178b

Please sign in to comment.