Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize percent literal delimiters #36

Merged
merged 2 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions lib/sharepoint/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def list_documents(list_name, conditions, site_path = nil, properties = [])
url = computed_web_api_url(site_path)
filter_param = "$filter=#{conditions}" if conditions.present?
expand_param = '$expand=Folder,File'
default_properties = %w(FileSystemObjectType UniqueId Title Created Modified File)
default_properties = %w[FileSystemObjectType UniqueId Title Created Modified File]
all_properties = default_properties + properties
select_param = "$select=#{all_properties.join(',')}"
url = "#{url}Lists/GetByTitle('#{odata_escape_single_quote(list_name)}')/Items?#{expand_param}&#{select_param}"
Expand Down Expand Up @@ -607,11 +607,14 @@ def uri_unescape(uri)
URI::DEFAULT_PARSER.unescape(uri.gsub('%5B', '[').gsub('%5D', ']'))
end

# TODO: Try to remove `eval` from this method. Otherwise, fix offenses
# rubocop:disable Security/Eval, Style/DocumentDynamicEvalDefinition, Style/EvalWithLocation, Style/PercentLiteralDelimiters
def string_unescape(s)
s.gsub!(/\\(?:[abfnrtv])/, '') # remove control chars
s.gsub!('"', '\"') # escape double quotes
eval %Q{"#{s}"}
end
# rubocop:enable Security/Eval, Style/DocumentDynamicEvalDefinition, Style/EvalWithLocation, Style/PercentLiteralDelimiters

def utf8_encode(s)
s.force_encoding('UTF-8') unless s.nil?
Expand Down Expand Up @@ -654,10 +657,10 @@ def build_search_fql_conditions(options)
end

def build_search_properties(options)
default_properties = %w(
default_properties = %w[
Write IsDocument IsContainer ListId WebId URL
Created Title Author Size Path UniqueId contentclass
)
]
properties = options[:properties] || []
properties += default_properties
"selectproperties='#{properties.join(',')}'"
Expand Down Expand Up @@ -696,7 +699,7 @@ def parse_list_response(json_response, all_properties)
record[key.underscore.to_sym] = result[key]
end
file = result['File']
%w(Name ServerRelativeUrl Length).each do |key|
%w[Name ServerRelativeUrl Length].each do |key|
record[key.underscore.to_sym] = file[key]
end
record[:url] = result['URL'].nil? ? nil : result['URL']['Url']
Expand All @@ -707,7 +710,7 @@ def parse_list_response(json_response, all_properties)

def parse_get_document_response(response_body, custom_properties)
all_props = JSON.parse(response_body)['d']
default_properties = %w(GUID Title Created Modified)
default_properties = %w[GUID Title Created Modified]
keys = default_properties + custom_properties
props = {}
keys.each do |key|
Expand Down