Menu

#1 NumberFormatException thrown in unhtmlentities

open
nobody
None
5
2006-11-27
2006-11-27
Anonymous
No

each of the following lines throws a NumberFormatException:

String test1 = HTMLEntities.unhtmlentities("&#;");
String test2 = HTMLEntities.unhtmlentities("&#x;");
String test3 = HTMLEntities.unhtmlentities("&#ab;");

the fix:

change
Integer iso;
to
Integer iso = null;

and change

if (entity.charAt(1) == '#') {
if (entity.charAt(2) == 'x') {
iso = new Integer(Integer.parseInt(entity.substring(3, entity.length() - 1), 16));
}
else {
iso = new Integer(entity.substring(2, entity.length() - 1));
}
} else {

to

if (entity.charAt(1) == '#') {
try {
if (entity.charAt(2) == 'x') {
iso = new Integer(Integer.parseInt(entity.substring(3, entity.length() - 1), 16));
}
else {
iso = new Integer(entity.substring(2, entity.length() - 1));
}
} catch (NumberFormatException e) {}
} else {

Discussion

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.