From 27c1df47172e30773bd6abcff1ef2bdc162dc7db Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Sun, 21 Apr 2024 13:15:27 +0200 Subject: [PATCH 1/2] Fix Style/PercentLiteralDelimiters --- .rubocop_todo.yml | 6 ------ lib/sharepoint/client.rb | 10 +++++----- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index eed9645..bd60467 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -134,12 +134,6 @@ Style/MutableConstant: Exclude: - 'lib/sharepoint/client.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Exclude: - - 'lib/sharepoint/client.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowedCompactTypes. # SupportedStyles: compact, exploded diff --git a/lib/sharepoint/client.rb b/lib/sharepoint/client.rb index 04edd39..e585476 100644 --- a/lib/sharepoint/client.rb +++ b/lib/sharepoint/client.rb @@ -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}" @@ -654,10 +654,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(',')}'" @@ -696,7 +696,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'] @@ -707,7 +707,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| From a938e65f513aefc4e3fd2b3e0ff3dc5e83fbf3f9 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Sun, 21 Apr 2024 13:21:32 +0200 Subject: [PATCH 2/2] Add a TODO to remove eval --- .rubocop_todo.yml | 13 ------------- lib/sharepoint/client.rb | 3 +++ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bd60467..3a38adc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -78,10 +78,6 @@ RSpec/AnyInstance: Exclude: - 'spec/lib/sharepoint/client_methods_spec.rb' -Security/Eval: - Exclude: - - 'lib/sharepoint/client.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. # SupportedStyles: always, conditionals @@ -96,10 +92,6 @@ Style/BarePercentLiterals: Exclude: - 'lib/sharepoint/client.rb' -Style/DocumentDynamicEvalDefinition: - Exclude: - - 'lib/sharepoint/client.rb' - # Configuration parameters: AllowedConstants. Style/Documentation: Exclude: @@ -107,11 +99,6 @@ Style/Documentation: - 'lib/sharepoint/errors.rb' - 'lib/sharepoint/spec_helpers.rb' -# This cop supports safe autocorrection (--autocorrect). -Style/EvalWithLocation: - Exclude: - - 'lib/sharepoint/client.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. # SupportedStyles: always, always_true, never diff --git a/lib/sharepoint/client.rb b/lib/sharepoint/client.rb index e585476..1ddec8d 100644 --- a/lib/sharepoint/client.rb +++ b/lib/sharepoint/client.rb @@ -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?