summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/worksheet/worksheet.rb
diff options
context:
space:
mode:
authorIan Clarkson <[email protected]>2019-12-16 09:17:41 -0800
committerStefan Daschek <[email protected]>2019-12-17 01:51:55 +0100
commit5d3f4a9b0f8c9474459e174cf22aeb8252f444ab (patch)
treeb911cee956d740a1ab3edb9bb9ce798b60b7acb3 /lib/axlsx/workbook/worksheet/worksheet.rb
parent75cec07c450378a597c8bbae1ca10229b6fb2bf1 (diff)
downloadcaxlsx-5d3f4a9b0f8c9474459e174cf22aeb8252f444ab.tar.gz
caxlsx-5d3f4a9b0f8c9474459e174cf22aeb8252f444ab.zip
Check size in bytes as opposed to string size
- `size` returns length in characters, but doesn't factor in multibyte Unicode characters. By switching to `bytesize`, we check the relevant measure of how many bytes the worksheet name is. - Fixes https://github.com/randym/axlsx/issues/588 - Copy of PR against original axlsx (https://github.com/randym/axlsx/pull/589)
Diffstat (limited to 'lib/axlsx/workbook/worksheet/worksheet.rb')
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index 6fbd384e..9cfefa51 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -656,7 +656,7 @@ module Axlsx
def validate_sheet_name(name)
DataTypeValidator.validate :worksheet_name, String, name
- raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % name) if name.size > 31
+ raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % name) if name.bytesize > 31
raise ArgumentError, (ERR_SHEET_NAME_CHARACTER_FORBIDDEN % name) if '[]*/\?:'.chars.any? { |char| name.include? char }
name = Axlsx::coder.encode(name)
sheet_names = @workbook.worksheets.reject { |s| s == self }.map { |s| s.name }