summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGeremia Taglialatela <[email protected]>2023-07-05 11:09:35 +0200
committerGeremia Taglialatela <[email protected]>2023-07-05 11:09:35 +0200
commitd52600dfb373323641c95c3c9be952c32fee8a1a (patch)
treee18b100cb29abb6dba3fcb0dbfa231fb6396fc65
parent692be9e99e0a76d5f6d0b0527466998ca558fe96 (diff)
downloadcaxlsx-d52600dfb373323641c95c3c9be952c32fee8a1a.tar.gz
caxlsx-d52600dfb373323641c95c3c9be952c32fee8a1a.zip
Fix offenses in sheet protection
- Lint/AmbiguousOperatorPrecedence - Style/PerlBackrefs - Style/StringChars - Style/UnpackFirst
-rw-r--r--.rubocop_todo.yml16
-rw-r--r--lib/axlsx/workbook/worksheet/sheet_protection.rb10
-rw-r--r--test/workbook/worksheet/tc_sheet_protection.rb2
3 files changed, 6 insertions, 22 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 29c93858..ac807d56 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -31,7 +31,6 @@ Layout/HashAlignment:
# This cop supports safe autocorrection (--autocorrect).
Lint/AmbiguousOperatorPrecedence:
Exclude:
- - 'lib/axlsx/workbook/worksheet/sheet_protection.rb'
- 'lib/axlsx/workbook/worksheet/worksheet.rb'
# This cop supports unsafe autocorrection (--autocorrect-all).
@@ -263,11 +262,6 @@ Style/PercentLiteralDelimiters:
- 'test/workbook/worksheet/tc_table_style_info.rb'
# This cop supports safe autocorrection (--autocorrect).
-Style/PerlBackrefs:
- Exclude:
- - 'test/workbook/worksheet/tc_sheet_protection.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: same_as_string_literals, single_quotes, double_quotes
Style/QuotedSymbols:
@@ -299,11 +293,6 @@ Style/SlicingWithRange:
- 'lib/axlsx/workbook/worksheet/pivot_table.rb'
- 'lib/axlsx/workbook/worksheet/worksheet.rb'
-# This cop supports unsafe autocorrection (--autocorrect-all).
-Style/StringChars:
- Exclude:
- - 'lib/axlsx/workbook/worksheet/sheet_protection.rb'
-
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
@@ -333,11 +322,6 @@ Style/TrivialAccessors:
- 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb'
# This cop supports safe autocorrection (--autocorrect).
-Style/UnpackFirst:
- Exclude:
- - 'lib/axlsx/workbook/worksheet/sheet_protection.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
Style/WhileUntilModifier:
Exclude:
- 'lib/axlsx/workbook/worksheet/color_scale.rb'
diff --git a/lib/axlsx/workbook/worksheet/sheet_protection.rb b/lib/axlsx/workbook/worksheet/sheet_protection.rb
index ce39b1b4..abf5e452 100644
--- a/lib/axlsx/workbook/worksheet/sheet_protection.rb
+++ b/lib/axlsx/workbook/worksheet/sheet_protection.rb
@@ -87,25 +87,25 @@ module Axlsx
encoded_password = encode_password(password)
password_as_hex = [encoded_password].pack("v")
- password_as_string = password_as_hex.unpack("H*").first.upcase
+ password_as_string = password_as_hex.unpack1("H*").upcase
password_as_string[2..3] + password_as_string[0..1]
end
# Encodes a given password
# Based on the algorithm provided by Daniel Rentz of OpenOffice.
- # http://www.openoffice.org/sc/excelfileformat.pdf, Revision 1.42, page 115 (21.05.2012)
+ # https://www.openoffice.org/sc/excelfileformat.pdf, Revision 1.42, page 115 (21.05.2012)
# @return [String]
def encode_password(password)
i = 0
- chars = password.split("")
+ chars = password.chars
count = chars.size
chars.collect! do |char|
i += 1
- char = char.unpack('c')[0] << i # ord << i
+ char = char.unpack1('c') << i # ord << i
low_15 = char & 0x7fff
- high_15 = char & 0x7fff << 15
+ high_15 = char & (0x7fff << 15)
high_15 = high_15 >> 15
low_15 | high_15
end
diff --git a/test/workbook/worksheet/tc_sheet_protection.rb b/test/workbook/worksheet/tc_sheet_protection.rb
index ebfff4b6..11a43ac8 100644
--- a/test/workbook/worksheet/tc_sheet_protection.rb
+++ b/test/workbook/worksheet/tc_sheet_protection.rb
@@ -57,7 +57,7 @@ class TestSheetProtection < Test::Unit::TestCase
doc = Nokogiri::XML(@sp.to_xml_string)
@options.each do |key, value|
- assert(doc.xpath("//sheetProtection[@#{key.to_s.gsub(/_(.)/) { $1.upcase }}='#{value}']"))
+ assert(doc.xpath("//sheetProtection[@#{key.to_s.gsub(/_(.)/) { ::Regexp.last_match(1).upcase }}='#{value}']"))
end
end
end