summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorZsolt Kozaroczy <[email protected]>2023-07-05 14:17:33 +0200
committerGitHub <[email protected]>2023-07-05 14:17:33 +0200
commitc7be63637220c57eb1b8d3afcff77a49aaa7a3ef (patch)
tree7b34212665e55d7a2b202de843aa37de571a25e7
parentd84f333fc3115025ddbc38c274cd6b2e818b4154 (diff)
parentd52600dfb373323641c95c3c9be952c32fee8a1a (diff)
downloadcaxlsx-c7be63637220c57eb1b8d3afcff77a49aaa7a3ef.tar.gz
caxlsx-c7be63637220c57eb1b8d3afcff77a49aaa7a3ef.zip
Merge pull request #293 from tagliala/chore/fix-offenses-in-sheet-protection
Fix offenses in sheet protection
-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