File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -63,8 +63,12 @@ def self.get_or_create_namespace_object(namespace_string)
6363 namespace_fedora_object
6464 end
6565
66+ def self . escape_path_or_uri_for_risearch_query ( path_or_uri )
67+ path_or_uri . gsub ( %q(') , %q(\\\') ) . gsub ( %q(:) , %q(\\\:) )
68+ end
69+
6670 def self . find_object_pid_by_filesystem_path ( full_filesystem_path , active_only = true )
67- query = "select $pid from <#ri> where $pid <http://purl.org/dc/elements/1.1/source> '#{ full_filesystem_path . gsub ( %q(') , %q(\\\') ) } '"
71+ query = "select $pid from <#ri> where $pid <http://purl.org/dc/elements/1.1/source> '#{ escape_path_or_uri_for_risearch_query ( full_filesystem_path ) } '"
6872 query += " and $pid <info:fedora/fedora-system:def/model#state> <fedora-model:Active>" if active_only
6973 ri_opts = {
7074 type : 'tuples' ,
Original file line number Diff line number Diff line change 11require 'rails_helper'
22
33RSpec . describe Hyacinth ::Utils ::FedoraUtils do
4-
5- context ".find_object_pid_by_filesystem_path" do
4+ describe ".find_object_pid_by_filesystem_path" do
65 it "escapes single quotes in file paths" do
76 full_filesystem_path = %q(/some/path/cool-o'something-irish-filename.pdf)
87 escaped_full_filesystem_path = %q(/some/path/cool-o\\'something-irish-filename.pdf)
3130 end
3231 end
3332
33+ describe '.escape_path_or_uri_for_risearch_query' do
34+ it 'does not modify a path with safe characters' do
35+ expect (
36+ described_class . escape_path_or_uri_for_risearch_query ( "/path/to/file.tiff" )
37+ ) . to eq (
38+ "/path/to/file.tiff"
39+ )
40+ end
41+
42+ it 'escapes a single quote in a path that contains single quote' do
43+ expect (
44+ described_class . escape_path_or_uri_for_risearch_query ( "/path/to/someone's-file.tiff" )
45+ ) . to eq (
46+ "/path/to/someone\\ 's-file.tiff"
47+ )
48+ end
49+
50+ it 'escapes a colon in a path that contains a colon' do
51+ expect (
52+ described_class . escape_path_or_uri_for_risearch_query ( 's3://bucket_name/path/to/file.tiff' )
53+ ) . to eq (
54+ "s3\\ ://bucket_name/path/to/file.tiff"
55+ )
56+ end
57+ end
3458end
You can’t perform that action at this time.
0 commit comments