summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorRandy Morgan (@morgan_randy) <[email protected]>2012-12-12 17:18:39 -0800
committerRandy Morgan (@morgan_randy) <[email protected]>2012-12-12 17:18:39 -0800
commitdb1f8da80d6507c84d83c3ca0b4e3c751d10d5e7 (patch)
tree794f5e13399fd4459c5a8461a36b03016ab4c1bd /lib
parent798e96feccea88648e64f1eb02707375f52cd50c (diff)
parent7362349b5c58f95f1eb8bbc35d5074a5e094d01f (diff)
downloadcaxlsx-db1f8da80d6507c84d83c3ca0b4e3c751d10d5e7.tar.gz
caxlsx-db1f8da80d6507c84d83c3ca0b4e3c751d10d5e7.zip
Merge pull request #153 from ball-hayden/master
Test for invalid characters in the sheet name
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/util/constants.rb5
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb2
2 files changed, 3 insertions, 4 deletions
diff --git a/lib/axlsx/util/constants.rb b/lib/axlsx/util/constants.rb
index 437de6db..f9bffa87 100644
--- a/lib/axlsx/util/constants.rb
+++ b/lib/axlsx/util/constants.rb
@@ -285,9 +285,8 @@ module Axlsx
# 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"
- # error message for sheets that use a name which includes a colon
-
- ERR_SHEET_NAME_COLON_FORBIDDEN = "Your worksheet name '%s' contains a colon, which is not allowed by MS Excel and will cause repair warnings. Please change the name of your sheet."
+ # error message for sheets that use a name which include invalid characters
+ ERR_SHEET_NAME_CHARACTER_FORBIDDEN = "Your worksheet name '%s' contains a character which is not allowed by MS Excel and will cause repair warnings. Please change the name of your sheet."
# error message for duplicate sheet names
ERR_DUPLICATE_SHEET_NAME = "There is already a worksheet in this workbook named '%s'. Please use a unique name"
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index 832b6f37..af2b2dfd 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -614,7 +614,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_COLON_FORBIDDEN % name) if name.include? ':'
+ raise ArgumentError, (ERR_SHEET_NAME_CHARACTER_FORBIDDEN % name) if '[]*/\?:'.chars.any? { |char| name.include? char }
name = Axlsx::coder.encode(name)
sheet_names = @workbook.worksheets.map { |s| s.name }
raise ArgumentError, (ERR_DUPLICATE_SHEET_NAME % name) if sheet_names.include?(name)