Skip to content

Commit

Permalink
Merge pull request #1474 from samvera/backports
Browse files Browse the repository at this point in the history
Backports
  • Loading branch information
cjcolvar authored Mar 7, 2022
2 parents 0d0337a + cf69b95 commit 8e6ea26
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
14 changes: 8 additions & 6 deletions active-fedora.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@ Gem::Specification.new do |s|
s.add_dependency 'faraday', '~> 0.12'
s.add_dependency 'faraday-encoding', '0.0.4'

s.add_development_dependency "rails"
s.add_development_dependency "equivalent-xml"
s.add_development_dependency 'fcrepo_wrapper', '~> 0.2'
s.add_development_dependency "github_changelog_generator"
s.add_development_dependency "rdoc"
s.add_development_dependency "yard"
s.add_development_dependency "psych", "< 4" # Restricted because 4.0+ do not work with rubocop 0.56.x
s.add_development_dependency "rails"
s.add_development_dependency "rake"
s.add_development_dependency "solr_wrapper", "~> 2.0"
s.add_development_dependency 'fcrepo_wrapper', '~> 0.2'
s.add_development_dependency "rspec", "~> 3.5"
s.add_development_dependency "rspec-its"
s.add_development_dependency "equivalent-xml"
s.add_development_dependency "simplecov", '~> 0.8'
s.add_development_dependency "rubocop", '~> 0.56.0'
s.add_development_dependency "rubocop-rspec", '~> 1.12.0'
s.add_development_dependency "simplecov", '~> 0.8'
s.add_development_dependency "solr_wrapper", "~> 2.0"
s.add_development_dependency "yard"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {spec}/*`.split("\n")
Expand Down
4 changes: 3 additions & 1 deletion lib/active_fedora.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
# Monkey patching RDF::Literal::DateTime to support fractional seconds.
# See https://github.com/samvera/active_fedora/issues/497
# Also monkey patches in a fix for timezones to be stored properly.
# This is needed in both RDF <= 3.2.4 and RDF >= 3.2.5
# TODO: Figure out how to contribute something upstream to avoid monkey-patching
module RDF
class Literal
class DateTime < Literal
class DateTime
ALTERNATIVE_FORMAT = '%Y-%m-%dT%H:%M:%S'.freeze
DOT = '.'.freeze
EMPTY = ''.freeze
Expand Down
2 changes: 1 addition & 1 deletion lib/active_fedora/core/fedora_id_translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module ActiveFedora::Core
class FedoraIdTranslator
SLASH = '/'.freeze
def self.call(id)
id = URI.escape(id, '[]'.freeze)
id = URI::DEFAULT_PARSER.escape(id, '[]'.freeze)
id = "/#{id}" unless id.start_with? SLASH
unless ActiveFedora.fedora.base_path == SLASH || id.start_with?("#{ActiveFedora.fedora.base_path}/")
id = ActiveFedora.fedora.base_path + id
Expand Down
2 changes: 1 addition & 1 deletion lib/active_fedora/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def retrieve_content

def ldp_headers
headers = { 'Content-Type'.freeze => mime_type, 'Content-Length'.freeze => content.size.to_s }
headers['Content-Disposition'.freeze] = "attachment; filename=\"#{URI.encode(@original_name)}\"" if @original_name
headers['Content-Disposition'.freeze] = "attachment; filename=\"#{URI::DEFAULT_PARSER.escape(@original_name)}\"" if @original_name
headers
end

Expand Down
26 changes: 25 additions & 1 deletion spec/integration/date_time_properties_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,33 @@ class Foo < ActiveFedora::Base

describe 'serializing' do
let(:object) { Foo.new(date: [date]) }
let(:triple) { object.resource.query(predicate: ::RDF::Vocab::DC.date).to_a.first }
let(:triple) { object.resource.query(predicate: ::RDF::Vocab::DC.date).to_a.first.object }
it 'time zone must have semicolin to be a cannonical XMLSchema#dateTime' do
expect(triple.to_s).to match(/\+01:00/)
end

context 'nanoseconds' do
let(:date) { DateTime.parse("2015-10-22T10:20:03.653991025+01:00") }

it 'includes nanosecond precision' do
expect(triple.to_s).to eq "2015-10-22T10:20:03.653991025+01:00"
end

context 'with trailing zeros' do
let(:date) { DateTime.parse("2015-10-22T15:34:20.97800000-11:00") }

it 'trims trailing zeros' do
expect(triple.to_s).to eq "2015-10-22T15:34:20.978-11:00"
end

context 'and only zero nanoseconds' do
let(:date) { DateTime.parse("2015-10-22T15:34:20.000000000-11:00") }

it 'trims trailing zeros and dot if nanoseconds are all 0' do
expect(triple.to_s).to eq "2015-10-22T15:34:20-11:00"
end
end
end
end
end
end

0 comments on commit 8e6ea26

Please sign in to comment.