diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index c0ce8db18..1a3771540 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 49875 - fixed XSSFWorkbook.createSheet to throw exception if sheet name begins or ends with a single quote (') 49873 - fixed XSSFFormulaEvaluator to support blank cells 49850 - added a getter for _iStartAt in ListFormatOverrideLevel 49761 - change cell type to error when setting Double.NaN or Infinities diff --git a/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java b/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java index 7f73a1dd1..073a0c3bd 100644 --- a/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java +++ b/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java @@ -26,6 +26,7 @@ import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.HexDump; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.StringUtil; +import org.apache.poi.ss.util.WorkbookUtil; /** * Title: Bound Sheet Record (aka BundleSheet) (0x0085)

@@ -90,42 +91,11 @@ public final class BoundSheetRecord extends StandardRecord { */ public void setSheetname(String sheetName) { - validateSheetName(sheetName); + WorkbookUtil.validateSheetName(sheetName); field_5_sheetname = sheetName; field_4_isMultibyteUnicode = StringUtil.hasMultibyte(sheetName) ? 1 : 0; } - private static void validateSheetName(String sheetName) { - if (sheetName == null) { - throw new IllegalArgumentException("sheetName must not be null"); - } - int len = sheetName.length(); - if (len < 1) { - throw new IllegalArgumentException("sheetName must not be empty string"); - } - for (int i=0; i + * The character count MUST be greater than or equal to 1 and less than or equal to 31. + * The string MUST NOT contain the any of the following characters: + *

+ * The string MUST NOT begin or end with the single quote (') character. + *

+ * + * @param sheetName the name to validate + */ + public static void validateSheetName(String sheetName) { + if (sheetName == null) { + throw new IllegalArgumentException("sheetName must not be null"); + } + int len = sheetName.length(); + if (len < 1) { + throw new IllegalArgumentException("sheetName must not be empty string"); + } + for (int i=0; i - * The character count MUST be greater than or equal to 1 and less than or equal to 31. - * The string MUST NOT contain the any of the following characters: - *
    - *
  • 0x0000
  • - *
  • 0x0003
  • - *
  • colon (:)
  • - *
  • backslash (\)
  • - *
  • asterisk (*)
  • - *
  • question mark (?)
  • - *
  • forward slash (/)
  • - *
  • opening square bracket ([)
  • - *
  • closing square bracket (])
  • - *
- * The string MUST NOT begin or end with the single quote (') character. - *

- * - * @param sheetName the name to validate - */ - private static void validateSheetName(String sheetName) { - if (sheetName == null) { - throw new IllegalArgumentException("sheetName must not be null"); - } - int len = sheetName.length(); - if (len < 1 || len > 31) { - throw new IllegalArgumentException("sheetName '" + sheetName - + "' is invalid - must be 1-30 characters long"); - } - for (int i=0; i diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java index c963f6ecc..67abf51b5 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java @@ -72,7 +72,8 @@ public abstract class BaseTestWorkbook extends TestCase { //names cannot be blank or contain any of /\*?[] String[] invalidNames = {"", "Sheet/", "Sheet\\", - "Sheet?", "Sheet*", "Sheet[", "Sheet]"}; + "Sheet?", "Sheet*", "Sheet[", "Sheet]", "'Sheet'", + "My:Sheet"}; for (String sheetName : invalidNames) { try { wb.createSheet(sheetName);