PR: 13921
Sheet name should not be greater than 31 chars and should not contain \/?*[] git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/branches/REL_2_BRANCH@353385 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
153364c993
commit
fd2cc4b7d1
@ -194,10 +194,22 @@ public class BoundSheetRecord
|
|||||||
/**
|
/**
|
||||||
* Set the sheetname for this sheet. (this appears in the tabs at the bottom)
|
* Set the sheetname for this sheet. (this appears in the tabs at the bottom)
|
||||||
* @param sheetname the name of the sheet
|
* @param sheetname the name of the sheet
|
||||||
|
* @thows IllegalArgumentException if sheet name will cause excel to crash.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void setSheetname( String sheetname )
|
public void setSheetname( String sheetname )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if ((sheetname == null) || (sheetname.length()==0)
|
||||||
|
|| (sheetname.length()>31)
|
||||||
|
|| (sheetname.indexOf("/") > -1)
|
||||||
|
|| (sheetname.indexOf("\\") > -1)
|
||||||
|
|| (sheetname.indexOf("?") > -1)
|
||||||
|
|| (sheetname.indexOf("*") > -1)
|
||||||
|
|| (sheetname.indexOf("]") > -1)
|
||||||
|
|| (sheetname.indexOf("[") > -1) ){
|
||||||
|
throw new IllegalArgumentException("Sheet name cannot be blank, greater than 31 chars, or contain any of /\\*?[]");
|
||||||
|
}
|
||||||
field_5_sheetname = sheetname;
|
field_5_sheetname = sheetname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +281,9 @@ public class HSSFWorkbook
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the sheet name.
|
* set the sheet name.
|
||||||
|
* Will throw IllegalArgumentException if the name is greater than 31 chars
|
||||||
|
* or contains /\?*[]
|
||||||
* @param sheet number (0 based)
|
* @param sheet number (0 based)
|
||||||
* @param sheet name
|
* @param sheet name
|
||||||
*/
|
*/
|
||||||
|
@ -92,5 +92,25 @@ public class TestBoundSheetRecord
|
|||||||
|
|
||||||
assertEquals(" 2 + 2 + 4 + 2 + 1 + 1 + len(str) * 2", 24, record.getRecordSize());
|
assertEquals(" 2 + 2 + 4 + 2 + 1 + 1 + len(str) * 2", 24, record.getRecordSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testName() {
|
||||||
|
BoundSheetRecord record = new BoundSheetRecord();
|
||||||
|
record.setSheetname("1234567890223456789032345678904");
|
||||||
|
assertTrue("Success", true);
|
||||||
|
try {
|
||||||
|
record.setSheetname("12345678902234567890323456789042");
|
||||||
|
assertTrue("Should have thrown IllegalArgumentException, but didnt", false);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
assertTrue("succefully threw exception",true);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
record.setSheetname("s//*s");
|
||||||
|
assertTrue("Should have thrown IllegalArgumentException, but didnt", false);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
assertTrue("succefully threw exception",true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user