From: Yegor Kozlov
Date: Sat, 4 Sep 2010 15:56:29 +0000 (+0000)
Subject: fixed XSSFWorkbook.createSheet to throw exception if sheet name begins or ends with...
X-Git-Tag: REL_3_7_BETA3~46
X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7bc987afea5aee517ece650c01d8f14031c76f74;p=poi.git
fixed XSSFWorkbook.createSheet to throw exception if sheet name begins or ends with a single quote ('), see Bugzilla 49875
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@992629 13f79535-47bb-0310-9956-ffa450edef68
---
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index c0ce8db185..1a3771540a 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 7f73a1dd18..073a0c3bd0 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:
+ *
+ * - 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
+ */
+ 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 c963f6eccc..67abf51b53 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);