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 randym#588.
  • Loading branch information
Ian Clarkson committed May 25, 2018
1 parent c593a08 commit d2e705e
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 d2e705e

Please sign in to comment.