Skip to content

Commit

Permalink
Merge pull request #560 from sul-dlss/manifest-url-encoding
Browse files Browse the repository at this point in the history
Remove URL-encoded slashes in IIIF manifest URLs
  • Loading branch information
thatbudakguy authored Jul 5, 2022
2 parents bb08ee8 + 1b02f9d commit b80ff91
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 55 deletions.
4 changes: 2 additions & 2 deletions app/models/iiif3_presentation_manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def body(controller = nil)
'label' => { en: [title] },
'requiredStatement' => iiif_key_value('Attribution', attribution),
'logo' => [{
'id' => 'https://stacks.stanford.edu/image/iiif/wy534zh7137%2FSULAIR_rosette/full/400,/0/default.jpg',
'id' => 'https://stacks.stanford.edu/image/iiif/wy534zh7137/SULAIR_rosette/full/400,/0/default.jpg',
'type' => 'Image',
'service' => [iiif_image_v2_service('https://stacks.stanford.edu/image/iiif/wy534zh7137%2FSULAIR_rosette')]
'service' => [iiif_image_v2_service('https://stacks.stanford.edu/image/iiif/wy534zh7137/SULAIR_rosette')]
}],
'seeAlso' => [{
'id' => controller.purl_url(druid, format: 'mods'),
Expand Down
6 changes: 3 additions & 3 deletions app/models/iiif_presentation_manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def body(controller = nil)
'label' => title,
'attribution' => copyright || 'Provided by the Stanford University Libraries',
'logo' => {
'@id' => 'https://stacks.stanford.edu/image/iiif/wy534zh7137%2FSULAIR_rosette/full/400,/0/default.jpg',
'service' => iiif_service('https://stacks.stanford.edu/image/iiif/wy534zh7137%2FSULAIR_rosette')
'@id' => 'https://stacks.stanford.edu/image/iiif/wy534zh7137/SULAIR_rosette/full/400,/0/default.jpg',
'service' => iiif_service('https://stacks.stanford.edu/image/iiif/wy534zh7137/SULAIR_rosette')
},
'seeAlso' => {
'@id' => controller.purl_url(druid, format: 'mods'),
Expand Down Expand Up @@ -357,7 +357,7 @@ def thumbnail?(file)
end

def stacks_iiif_base_url(druid, filename)
"#{Settings.stacks.url}/image/iiif/#{druid}%2F#{ERB::Util.url_encode(File.basename(filename, '.*'))}"
"#{Settings.stacks.url}/image/iiif/#{druid}/#{ERB::Util.url_encode(File.basename(filename, '.*'))}"
end

def stacks_file_url(druid, filename)
Expand Down
16 changes: 8 additions & 8 deletions spec/features/iiif3_manifest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
expect(json['seeAlso'].first['id']).to eq 'http://www.example.com/bb157hs6068.mods'
expect(json['thumbnail']).to be_an Array
expect(json['thumbnail'].size).to eq 1
expect(json['thumbnail'].first['id']).to eq 'https://stacks.stanford.edu/image/iiif/bb157hs6068%2Fbb157hs6068_05_0001/full/!400,400/0/default.jpg'
expect(json['thumbnail'].first['id']).to eq 'https://stacks.stanford.edu/image/iiif/bb157hs6068/bb157hs6068_05_0001/full/!400,400/0/default.jpg'

expect(json['items'].length).to eq 1
canvas = json['items'].first
Expand All @@ -25,7 +25,7 @@
image = canvas['items'].first['items'].first
expect(image['body']['height']).to eq 9040
expect(image['body']['width']).to eq 10_481
expect(image['body']['id']).to eq 'https://stacks.stanford.edu/image/iiif/bb157hs6068%2Fbb157hs6068_05_0001/full/full/0/default.jpg'
expect(image['body']['id']).to eq 'https://stacks.stanford.edu/image/iiif/bb157hs6068/bb157hs6068_05_0001/full/full/0/default.jpg'

expect(json['metadata'].class).to eq Array
expect(json['metadata'].size).to eq(13) # 11 DC elements grouped by name are there + the publish date + Available Online
Expand Down Expand Up @@ -63,7 +63,7 @@

expect(json['thumbnail']).to be_an Array
expect(json['thumbnail'].size).to eq 1
expect(json['thumbnail'].first['id']).to eq 'https://stacks.stanford.edu/image/iiif/bb157hs6068%2Fbb157hs6068_05_0001/full/!400,400/0/default.jpg'
expect(json['thumbnail'].first['id']).to eq 'https://stacks.stanford.edu/image/iiif/bb157hs6068/bb157hs6068_05_0001/full/!400,400/0/default.jpg'
expect(json['thumbnail'].first['type']).to eq 'Image'
expect(json['thumbnail'].first['width']).to eq 400
expect(json['thumbnail'].first['height']).to eq 345
Expand Down Expand Up @@ -169,7 +169,7 @@
expect(canvas['label']['en'].first).to eq 'Image 1'

image = canvas['items'].first['items'].first
expect(image['body']['id']).to end_with '/image/iiif/cg767mn6478%2F2542A/full/full/0/default.jpg'
expect(image['body']['id']).to end_with '/image/iiif/cg767mn6478/2542A/full/full/0/default.jpg'
expect(image['body']['height']).to eq 4747
expect(image['body']['width']).to eq 6475
end
Expand All @@ -192,7 +192,7 @@
expect(canvas['label']['en'].first).to eq 'Image 1'

image = canvas['items'].first['items'].first
expect(image['body']['id']).to end_with '/image/iiif/jw923xn5254%2F2542B/full/full/0/default.jpg'
expect(image['body']['id']).to end_with '/image/iiif/jw923xn5254/2542B/full/full/0/default.jpg'
expect(image['body']['height']).to eq 4675
expect(image['body']['width']).to eq 3139
end
Expand All @@ -209,7 +209,7 @@
expect(json['label']['en'].first).to start_with 'Carey\'s American Atlas'
expect(json['thumbnail']).to be_an Array
expect(json['thumbnail'].size).to eq 1
expect(json['thumbnail'].first['id']).to end_with '/image/iiif/cg767mn6478%2F2542A/full/!400,400/0/default.jpg' # first child
expect(json['thumbnail'].first['id']).to end_with '/image/iiif/cg767mn6478/2542A/full/!400,400/0/default.jpg' # first child
expect(json['items'].length).to eq 23

canvas = json['items'].first
Expand All @@ -218,7 +218,7 @@
expect(canvas['items'].length).to eq 1
expect(canvas['items'].first['items'].length).to eq 1
image = canvas['items'].first['items'].first
expect(image['body']['id']).to end_with '/image/iiif/cg767mn6478%2F2542A/full/full/0/default.jpg' # first child
expect(image['body']['id']).to end_with '/image/iiif/cg767mn6478/2542A/full/full/0/default.jpg' # first child
expect(image['body']['height']).to eq 4747
expect(image['body']['width']).to eq 6475

Expand All @@ -228,7 +228,7 @@
expect(canvas['items'].length).to eq 1
expect(canvas['items'].first['items'].length).to eq 1
image = canvas['items'].first['items'].first
expect(image['body']['id']).to end_with '/image/iiif/jw923xn5254%2F2542B/full/full/0/default.jpg' # second child
expect(image['body']['id']).to end_with '/image/iiif/jw923xn5254/2542B/full/full/0/default.jpg' # second child
expect(image['body']['height']).to eq 4675
expect(image['body']['width']).to eq 3139
end
Expand Down
26 changes: 13 additions & 13 deletions spec/features/iiif_manifest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
expect(json['description']).to eq 'Tom.1. No.9. (top right).'
expect(json['attribution']).to start_with 'This work has been identified as being free of known restrictions'
expect(json['seeAlso']['@id']).to eq 'http://www.example.com/bb157hs6068.mods'
expect(json['thumbnail']['@id']).to eq 'https://stacks.stanford.edu/image/iiif/bb157hs6068%2Fbb157hs6068_05_0001/full/!400,400/0/default.jpg'
expect(json['thumbnail']['@id']).to eq 'https://stacks.stanford.edu/image/iiif/bb157hs6068/bb157hs6068_05_0001/full/!400,400/0/default.jpg'

expect(json['sequences'].length).to eq 1
canvas = json['sequences'].first['canvases'].first
Expand All @@ -23,7 +23,7 @@

expect(image['resource']['height']).to eq 9040
expect(image['resource']['width']).to eq 10_481
expect(image['resource']['@id']).to eq 'https://stacks.stanford.edu/image/iiif/bb157hs6068%2Fbb157hs6068_05_0001/full/full/0/default.jpg'
expect(image['resource']['@id']).to eq 'https://stacks.stanford.edu/image/iiif/bb157hs6068/bb157hs6068_05_0001/full/full/0/default.jpg'

expect(json['metadata'].class).to eq Array
expect(json['metadata'].size).to eq(22) # 20 DC elements are there + the publish date + Available Online
Expand Down Expand Up @@ -60,7 +60,7 @@
visit '/bb157hs6068/iiif/manifest.json'
json = JSON.parse(page.body)

expect(json['thumbnail']['@id']).to eq 'https://stacks.stanford.edu/image/iiif/bb157hs6068%2Fbb157hs6068_05_0001/full/!400,400/0/default.jpg'
expect(json['thumbnail']['@id']).to eq 'https://stacks.stanford.edu/image/iiif/bb157hs6068/bb157hs6068_05_0001/full/!400,400/0/default.jpg'
expect(json['thumbnail']['@type']).to eq 'dctypes:Image'
expect(json['thumbnail']['width']).to eq 400
expect(json['thumbnail']['height']).to eq 345
Expand All @@ -69,13 +69,13 @@
it 'includes the representative thumbnail as part of the image sequence' do
visit '/rf433wv2584/iiif/manifest.json'
json = JSON.parse(page.body)
expect(json['thumbnail']['@id']).to eq 'https://stacks.stanford.edu/image/iiif/rf433wv2584%2F9082000/full/!400,400/0/default.jpg'
expect(json['thumbnail']['@id']).to eq 'https://stacks.stanford.edu/image/iiif/rf433wv2584/9082000/full/!400,400/0/default.jpg'

expect(json['sequences'].length).to eq 1
canvas = json['sequences'].first['canvases'].first
expect(canvas['images'].length).to eq 1
image = canvas['images'].first
expect(image['resource']['@id']).to eq 'https://stacks.stanford.edu/image/iiif/rf433wv2584%2F9082000/full/full/0/default.jpg'
expect(image['resource']['@id']).to eq 'https://stacks.stanford.edu/image/iiif/rf433wv2584/9082000/full/full/0/default.jpg'
end

it 'includes canvas rendering of jp2 if downloadable' do
Expand Down Expand Up @@ -272,7 +272,7 @@
expect(canvas['label']).to eq 'Image 1'

image = canvas['images'].first
expect(image['resource']['@id']).to end_with '/image/iiif/cg767mn6478%2F2542A/full/full/0/default.jpg'
expect(image['resource']['@id']).to end_with '/image/iiif/cg767mn6478/2542A/full/full/0/default.jpg'
expect(image['resource']['height']).to eq 4747
expect(image['resource']['width']).to eq 6475
end
Expand All @@ -295,7 +295,7 @@
expect(canvas['label']).to eq 'Image 1'

image = canvas['images'].first
expect(image['resource']['@id']).to end_with '/image/iiif/jw923xn5254%2F2542B/full/full/0/default.jpg'
expect(image['resource']['@id']).to end_with '/image/iiif/jw923xn5254/2542B/full/full/0/default.jpg'
expect(image['resource']['height']).to eq 4675
expect(image['resource']['width']).to eq 3139
end
Expand All @@ -310,7 +310,7 @@

json = JSON.parse(page.body)
expect(json['label']).to start_with 'Carey\'s American Atlas'
expect(json['thumbnail']['@id']).to end_with '/image/iiif/cg767mn6478%2F2542A/full/!400,400/0/default.jpg' # first child
expect(json['thumbnail']['@id']).to end_with '/image/iiif/cg767mn6478/2542A/full/!400,400/0/default.jpg' # first child
expect(json['sequences'].length).to eq 1
expect(json['sequences'].first['canvases'].length).to eq 23

Expand All @@ -319,7 +319,7 @@

expect(canvas['images'].length).to eq 1
image = canvas['images'].first
expect(image['resource']['@id']).to end_with '/image/iiif/cg767mn6478%2F2542A/full/full/0/default.jpg' # first child
expect(image['resource']['@id']).to end_with '/image/iiif/cg767mn6478/2542A/full/full/0/default.jpg' # first child
expect(image['resource']['height']).to eq 4747
expect(image['resource']['width']).to eq 6475

Expand All @@ -328,7 +328,7 @@

expect(canvas['images'].length).to eq 1
image = canvas['images'].first
expect(image['resource']['@id']).to end_with '/image/iiif/jw923xn5254%2F2542B/full/full/0/default.jpg' # second child
expect(image['resource']['@id']).to end_with '/image/iiif/jw923xn5254/2542B/full/full/0/default.jpg' # second child
expect(image['resource']['height']).to eq 4675
expect(image['resource']['width']).to eq 3139
end
Expand Down Expand Up @@ -364,13 +364,13 @@
image_ids = json['sequences'].flat_map { |x| x['canvases'] }.flat_map { |x| x['images'] }.map { |x| x['resource']['@id'] }

# handle spaces
expect(image_ids).to include 'https://stacks.stanford.edu/image/iiif/fg019pm1396%2FJungleCat%20x/full/full/0/default.jpg'
expect(image_ids).to include 'https://stacks.stanford.edu/image/iiif/fg019pm1396/JungleCat%20x/full/full/0/default.jpg'

# handle percent signs
expect(image_ids).to include 'https://stacks.stanford.edu/image/iiif/fg019pm1396%2FJungleCat%2520x/full/full/0/default.jpg'
expect(image_ids).to include 'https://stacks.stanford.edu/image/iiif/fg019pm1396/JungleCat%2520x/full/full/0/default.jpg'

# xml escaped stuff
expect(image_ids).to include 'https://stacks.stanford.edu/image/iiif/fg019pm1396%2FJungleCat%26x/full/full/0/default.jpg'
expect(image_ids).to include 'https://stacks.stanford.edu/image/iiif/fg019pm1396/JungleCat%26x/full/full/0/default.jpg'
end
end
end
12 changes: 6 additions & 6 deletions spec/fixtures/iiif_manifests/v2/image_bx658jh7339.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"label": "M. de Courville : [estampe]",
"attribution": "Provided by the Stanford University Libraries",
"logo": {
"@id": "https://stacks.stanford.edu/image/iiif/wy534zh7137%2FSULAIR_rosette/full/400,/0/default.jpg",
"@id": "https://stacks.stanford.edu/image/iiif/wy534zh7137/SULAIR_rosette/full/400,/0/default.jpg",
"service": {
"@context": "http://iiif.io/api/image/2/context.json",
"@id": "https://stacks.stanford.edu/image/iiif/wy534zh7137%2FSULAIR_rosette",
"@id": "https://stacks.stanford.edu/image/iiif/wy534zh7137/SULAIR_rosette",
"profile": "http://iiif.io/api/image/2/level1.json"
}
},
Expand Down Expand Up @@ -78,12 +78,12 @@
"value": "2013-12-14T16:51:21-08:00"
}],
"thumbnail": {
"@id": "https://stacks.stanford.edu/image/iiif/bx658jh7339%2FT0000001/full/!400,400/0/default.jpg",
"@id": "https://stacks.stanford.edu/image/iiif/bx658jh7339/T0000001/full/!400,400/0/default.jpg",
"@type": "dctypes:Image",
"format": "image/jpeg",
"service": {
"@context": "http://iiif.io/api/image/2/context.json",
"@id": "https://stacks.stanford.edu/image/iiif/bx658jh7339%2FT0000001",
"@id": "https://stacks.stanford.edu/image/iiif/bx658jh7339/T0000001",
"profile": "http://iiif.io/api/image/2/level1.json"
}
},
Expand All @@ -102,14 +102,14 @@
"@type": "oa:Annotation",
"motivation": "sc:painting",
"resource": {
"@id": "https://stacks.stanford.edu/image/iiif/bx658jh7339%2FT0000001/full/full/0/default.jpg",
"@id": "https://stacks.stanford.edu/image/iiif/bx658jh7339/T0000001/full/full/0/default.jpg",
"@type": "dctypes:Image",
"format": "image/jpeg",
"height": 2608,
"width": 1680,
"service": {
"@context": "http://iiif.io/api/image/2/context.json",
"@id": "https://stacks.stanford.edu/image/iiif/bx658jh7339%2FT0000001",
"@id": "https://stacks.stanford.edu/image/iiif/bx658jh7339/T0000001",
"profile": "http://iiif.io/api/image/2/level1.json"
}
},
Expand Down
6 changes: 3 additions & 3 deletions spec/fixtures/iiif_manifests/v3/3D_hc941fm6529.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"label":"Sheep (Ovis aries), male, cervical vertabra",
"attribution":"Provided by the Stanford University Libraries",
"logo":{
"@id":"https://stacks.stanford.edu/image/iiif/wy534zh7137%2FSULAIR_rosette/full/400,/0/default.jpg",
"@id":"https://stacks.stanford.edu/image/iiif/wy534zh7137/SULAIR_rosette/full/400,/0/default.jpg",
"service":{
"@context":"http://iiif.io/api/image/2/context.json",
"@id":"https://stacks.stanford.edu/image/iiif/wy534zh7137%2FSULAIR_rosette",
"@id":"https://stacks.stanford.edu/image/iiif/wy534zh7137/SULAIR_rosette",
"profile":"http://iiif.io/api/image/2/level1.json"
}
},
Expand Down Expand Up @@ -59,4 +59,4 @@
]
}
]
}
}
12 changes: 6 additions & 6 deletions spec/fixtures/iiif_manifests/v3/image_bx658jh7339.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"label": "M. de Courville : [estampe]",
"attribution": "Provided by the Stanford University Libraries",
"logo": {
"id": "https://stacks.stanford.edu/image/iiif/wy534zh7137%2FSULAIR_rosette/full/400,/0/default.jpg",
"id": "https://stacks.stanford.edu/image/iiif/wy534zh7137/SULAIR_rosette/full/400,/0/default.jpg",
"service": {
"@context": "http://iiif.io/api/image/2/context.json",
"id": "https://stacks.stanford.edu/image/iiif/wy534zh7137%2FSULAIR_rosette",
"id": "https://stacks.stanford.edu/image/iiif/wy534zh7137/SULAIR_rosette",
"profile": "http://iiif.io/api/image/2/level1.json"
}
},
Expand Down Expand Up @@ -78,12 +78,12 @@
"value": "2013-12-14T16:51:21-08:00"
}],
"thumbnail": [{
"id": "https://stacks.stanford.edu/image/iiif/bx658jh7339%2FT0000001/full/!400,400/0/default.jpg",
"id": "https://stacks.stanford.edu/image/iiif/bx658jh7339/T0000001/full/!400,400/0/default.jpg",
"type": "dctypes:Image",
"format": "image/jpeg",
"service": {
"@context": "http://iiif.io/api/image/2/context.json",
"id": "https://stacks.stanford.edu/image/iiif/bx658jh7339%2FT0000001",
"id": "https://stacks.stanford.edu/image/iiif/bx658jh7339/T0000001",
"profile": "http://iiif.io/api/image/2/level1.json"
}
}],
Expand All @@ -105,13 +105,13 @@
"type": "dctypes:Image",
"motivation": "painting",
"body": {
"id": "https://stacks.stanford.edu/image/iiif/bx658jh7339%2FT0000001/full/full/0/default.jpg",
"id": "https://stacks.stanford.edu/image/iiif/bx658jh7339/T0000001/full/full/0/default.jpg",
"format": "image/jpeg",
"height": 2608,
"width": 1680,
"service": {
"@context": "http://iiif.io/api/image/2/context.json",
"id": "https://stacks.stanford.edu/image/iiif/bx658jh7339%2FT0000001",
"id": "https://stacks.stanford.edu/image/iiif/bx658jh7339/T0000001",
"profile": "http://iiif.io/api/image/2/level1.json"
},
"target": "https://purl.stanford.edu/bx658jh7339/iiif3/canvas/bx658jh7339_1"
Expand Down
10 changes: 5 additions & 5 deletions spec/fixtures/iiif_manifests/v3/image_rf200sq2539.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"label":"PC0002_353_poetry_and_prose_scene_at_monument_point_north_end_of_salt_lake",
"attribution":"Provided by the Stanford University Libraries",
"logo":{
"@id":"https://stacks.stanford.edu/image/iiif/wy534zh7137%2FSULAIR_rosette/full/400,/0/default.jpg",
"@id":"https://stacks.stanford.edu/image/iiif/wy534zh7137/SULAIR_rosette/full/400,/0/default.jpg",
"service":{
"@context":"http://iiif.io/api/image/2/context.json",
"@id":"https://stacks.stanford.edu/image/iiif/wy534zh7137%2FSULAIR_rosette",
"@id":"https://stacks.stanford.edu/image/iiif/wy534zh7137/SULAIR_rosette",
"profile":"http://iiif.io/api/image/2/level1.json"
}
},
Expand Down Expand Up @@ -49,12 +49,12 @@
"width":5860,
"height":5027,
"body":{
"id":"https://stacks.stanford.edu/image/iiif/rf200sq2539%2FPC0002_356_the_last_rail_is_laid_scene_at_promontory_point_may_10_1869/full/full/0/default.jpg",
"id":"https://stacks.stanford.edu/image/iiif/rf200sq2539/PC0002_356_the_last_rail_is_laid_scene_at_promontory_point_may_10_1869/full/full/0/default.jpg",
"type":"Image",
"format":"image/jpeg",
"service": {
"@context": "http://iiif.io/api/image/2/context.json",
"@id": "https://stacks.stanford.edu/image/iiif/rf200sq2539%2FPC0002_356_the_last_rail_is_laid_scene_at_promontory_point_may_10_1869",
"@id": "https://stacks.stanford.edu/image/iiif/rf200sq2539/PC0002_356_the_last_rail_is_laid_scene_at_promontory_point_may_10_1869",
"profile": "http://iiif.io/api/image/2/level1.json"
}
},
Expand All @@ -67,4 +67,4 @@
]
}
]
}
}
4 changes: 2 additions & 2 deletions spec/fixtures/iiif_manifests/v3/pdf_bh502xm3351.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"label":"The CATGUT Acoustical Society Newsletter: Number 20, Nov. 1973",
"attribution":"Provided by the Stanford University Libraries",
"logo":{
"@id":"https://stacks.stanford.edu/image/iiif/wy534zh7137%2FSULAIR_rosette/full/400,/0/default.jpg",
"@id":"https://stacks.stanford.edu/image/iiif/wy534zh7137/SULAIR_rosette/full/400,/0/default.jpg",
"service":{
"@context":"http://iiif.io/api/image/2/context.json",
"@id":"https://stacks.stanford.edu/image/iiif/wy534zh7137%2FSULAIR_rosette",
"@id":"https://stacks.stanford.edu/image/iiif/wy534zh7137/SULAIR_rosette",
"profile":"http://iiif.io/api/image/2/level1.json"
}
},
Expand Down
Loading

0 comments on commit b80ff91

Please sign in to comment.