summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorNoel Peden <[email protected]>2022-02-07 08:30:19 -0800
committerGitHub <[email protected]>2022-02-07 08:30:19 -0800
commit1def0a01e9af324ecf202e6542fa77920dc11662 (patch)
tree1f8367b7f7bf29bfacc2ae593d3e9870fcaaafd7 /lib
parentbe9b3e6ee9dca0e0377ae8f3b14d007ad494b7e6 (diff)
parentc027feff583a09d5d6803e666bdbfca87653329d (diff)
downloadcaxlsx-1def0a01e9af324ecf202e6542fa77920dc11662.tar.gz
caxlsx-1def0a01e9af324ecf202e6542fa77920dc11662.zip
Merge pull request #116 from caxlsx/empty-sheet-name
Validate name option to be non-empty string when passed.
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/util/constants.rb3
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb1
2 files changed, 4 insertions, 0 deletions
diff --git a/lib/axlsx/util/constants.rb b/lib/axlsx/util/constants.rb
index 3d67088c..76db47bb 100644
--- a/lib/axlsx/util/constants.rb
+++ b/lib/axlsx/util/constants.rb
@@ -286,6 +286,9 @@ module Axlsx
# error message for RangeValidator
ERR_RANGE = "Invalid Data. %s must be between %s and %s, (inclusive:%s) you gave: %s".freeze
+ # error message for sheets that use explicit empty string name
+ ERR_SHEET_NAME_EMPTY = "Your worksheet name is empty. Worksheet name can't be empty. Please assign name of your sheet or don't use name option at all.".freeze
+
# error message for sheets that use a name which is longer than 31 bytes
ERR_SHEET_NAME_TOO_LONG = "Your worksheet name '%s' is too long. Worksheet names must be 31 characters (bytes) or less".freeze
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index adb9839f..0942daa2 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -682,6 +682,7 @@ module Axlsx
def validate_sheet_name(name)
DataTypeValidator.validate :worksheet_name, String, name
# ignore first character (BOM) after encoding to utf16 because Excel does so, too.
+ raise ArgumentError, (ERR_SHEET_NAME_EMPTY) if name.empty?
character_length = name.encode("utf-16")[1..-1].encode("utf-16").bytesize / 2
raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % name) if character_length > 31
raise ArgumentError, (ERR_SHEET_NAME_CHARACTER_FORBIDDEN % name) if '[]*/\?:'.chars.any? { |char| name.include? char }