Skip to content

Commit

Permalink
Check size in bytes as opposed to string size
Browse files Browse the repository at this point in the history
- `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
- Copy of PR against original axlsx
(#589)
  • Loading branch information
Ian Clarkson committed Dec 16, 2019
1 parent 75cec07 commit cfce288
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/axlsx/workbook/worksheet/worksheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit cfce288

Please sign in to comment.