Bug 64788 - Text validation in createPromptBox doesn't read _x000a_ line break as one caracter
Summary: Text validation in createPromptBox doesn't read _x000a_ line break as one car...
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 4.1.2-FINAL
Hardware: All All
: P1 trivial (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-06 14:40 UTC by yanick.savanier@douane.finances.gouv.fr
Modified: 2020-10-09 10:07 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description yanick.savanier@douane.finances.gouv.fr 2020-10-06 14:40:20 UTC
Currently a data validation occuring in createPromptBox on the prompt text is checking whether text is longuer than 255 omiting the fact that line break entities are transcoded as _x000a_ text and thus failing the test while in reality  _x000a_ is seens as 1 caracter by excel.

As a solution you may check length on a string wich is obtained by replacing _x000a_ or _x000a_ and _x000d_  as a dummy character before testing its length against the 255 caracters limit :

if(text != null && text.length() > 255) {
			throw new IllegalStateException("Prompt-text cannot be longer than 255 characters, but had: " + text);
}

===>

if(text != null && text.replace("_x000a_","_").replace("_x000d_","_").length() > 255) {
			throw new IllegalStateException("Prompt-text cannot be longer than 255 characters, but had: " + text);
}
Comment 1 yanick.savanier@douane.finances.gouv.fr 2020-10-06 14:41:11 UTC
I'm talking about org.apache.poi.hssf.usermodel.HSSFDataValidation class by the way
Comment 2 yanick.savanier@douane.finances.gouv.fr 2020-10-06 14:41:42 UTC
and about org.apache.poi.hssf.usermodel.XSSFDataValidation class
Comment 3 yanick.savanier@douane.finances.gouv.fr 2020-10-06 14:42:46 UTC
Errr org.apache.poi.xssf.usermodel.XSSFDataValidation sorry
Comment 4 yanick.savanier@douane.finances.gouv.fr 2020-10-06 14:45:14 UTC
So for org.apache.poi.xssf.usermodel.XSSFDataValidation that might be more like :

if(text != null && text.length() > MAX_TEXT_LENGTH) {
			throw new IllegalStateException("Error-text cannot be longer than 255 characters, but had: " + text);
}

===>

if(text != null && text.replace("_x000a_","_").replace("_x000d_","_").length() > MAX_TEXT_LENGTH) {
			throw new IllegalStateException("Error-text cannot be longer than 255 characters, but had: " + text);
}
Comment 5 PJ Fanning 2020-10-06 15:02:24 UTC
it would probably be better to assume that all sequences like `_x000a_` are counted as one char when getting the length

the 4 chars after the _x can be checked to see if they are valid hexadecimal digits
Comment 6 yanick.savanier@douane.finances.gouv.fr 2020-10-07 11:58:17 UTC
Yeah that would be better as for example a regexp like 

 .replaceAll("_x[0-9a-f]{4}_", "ยค")
Comment 7 yanick.savanier@douane.finances.gouv.fr 2020-10-09 10:07:52 UTC
Sorry I didn't saw that encodeUtf method was already converting \n to _x000a_ so I wasn't supposed to do it before calling setPrompt...

Sorry for the unconvenience... 

Cheers