riiif 2.0.0.beta1 → 2.0.0.beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e944a8c92ae1774d9dd42515c3202a18b6a70f64
|
4
|
+
data.tar.gz: a4fa5460db8fc3703f21d3c8a07a62b920e4aa5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33d4db4a5c49e09845ecdac04bdd35d88fa3ab1526eab8fbdd55bfbde786aee6adc1843e90e4f2bf0389c83570c005cb143e1dc831c18ec664fde6919a7feb6e
|
7
|
+
data.tar.gz: '05628c076ffc69365d0821f368118d0e078d7bbae5c946f4f59fafc485d8948d56b954338f0dfbdb4b8628212d48954b1a972fc937e4099985b97f67ca12ba9b'
|
@@ -2,13 +2,28 @@ module Riiif
|
|
2
2
|
class FileSystemFileResolver < AbstractFileSystemResolver
|
3
3
|
attr_writer :input_types
|
4
4
|
|
5
|
+
# @return a string suitable for a globbing match
|
6
|
+
# e.g. /base/path/67352ccc-d1b0-11e1-89ae-279075081939.{jp2,tiff,png}
|
7
|
+
# or nil when the id is not valid
|
5
8
|
def pattern(id)
|
6
|
-
|
9
|
+
return unless validate_identifier(id: id)
|
7
10
|
::File.join(base_path, "#{id}.{#{input_types.join(',')}}")
|
8
11
|
end
|
9
12
|
|
10
13
|
private
|
11
14
|
|
15
|
+
# @return [Boolean] true if the id matches the regex
|
16
|
+
def validate_identifier(id:, regex: identifier_regex)
|
17
|
+
return true if id =~ regex
|
18
|
+
Rails.logger.warn "Invalid characters in id `#{id}`"
|
19
|
+
false
|
20
|
+
end
|
21
|
+
|
22
|
+
# Matches on word characters dashes and colons
|
23
|
+
def identifier_regex
|
24
|
+
/^[\w\-:]+$/
|
25
|
+
end
|
26
|
+
|
12
27
|
def input_types
|
13
28
|
@input_types ||= %w(png jpg tif tiff jp2)
|
14
29
|
end
|
data/lib/riiif/version.rb
CHANGED
@@ -21,6 +21,14 @@ describe Riiif::FileSystemFileResolver do
|
|
21
21
|
expect(subject.path).to eq base_path + '/world.jp2'
|
22
22
|
end
|
23
23
|
end
|
24
|
+
|
25
|
+
context 'when pattern is not permitted' do
|
26
|
+
let(:id) { 'foo/bar' } # slashes are not permitted by default
|
27
|
+
|
28
|
+
it 'casts the error to a not found (required by the IIIF spec)' do
|
29
|
+
expect { subject.path }.to raise_error Riiif::ImageNotFoundError
|
30
|
+
end
|
31
|
+
end
|
24
32
|
end
|
25
33
|
|
26
34
|
describe '#input_types' do
|
@@ -63,5 +71,12 @@ describe Riiif::FileSystemFileResolver do
|
|
63
71
|
expect { subject }.not_to raise_error
|
64
72
|
end
|
65
73
|
end
|
74
|
+
|
75
|
+
context 'with slashes (unallowed by default)' do
|
76
|
+
let(:id) { 'fo/baz' }
|
77
|
+
it 'returns nil' do
|
78
|
+
expect(subject).to be_nil
|
79
|
+
end
|
80
|
+
end
|
66
81
|
end
|
67
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riiif
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|