From d2e705e339689b2dd6741645b67e2dc4dd572760 Mon Sep 17 00:00:00 2001 From: Ian Clarkson Date: Fri, 25 May 2018 15:29:22 -0700 Subject: [PATCH] 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 #588. --- lib/axlsx/workbook/worksheet/worksheet.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 @@ def outline(collection, range, level = 1, collapsed = true) 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 }