ERXBrowserFactory - parseVersion does not work correct in some cases
ERXBrowserFactory - parseVersion does not work correct in some cases
- Subject: ERXBrowserFactory - parseVersion does not work correct in some cases
- From: Stefan Klein <email@hidden>
- Date: Wed, 08 Feb 2012 00:51:00 +0100
Hi,
in last times i got some NumberFormat exception from
ERXBasicBrowser.
The contents of user-agent are:
"Mozilla/5.0 (compatible; MJ12bot/v1.4.1;
http://www.majestic12.co.uk/bot.php?+)"
"SonyEricssonJ20i/R7BA Browser/NetFront/3.5 Profile/MIDP-2.1
Configuration/CLDC-1.1 JavaPlatform/JP-8.5.2"
I guess, the real problem comes from ERXBrowserFactory.parseVersion().
I don't think it is worse to build a better parser for all possible
user-agents, so I suggest the best way would be to check if we got a
real number.
public String parseVersion(String userAgent) {
String versionString = _versionString(userAgent);
int startpos;
String version = ERXBrowser.UNKNOWN_VERSION;
// Remove "Netscape6" from string such as "Netscape6/6.2.3",
// otherwise this method will produce wrong result "6/6.2.3"
as the
// version
final String netscape6 = "Netscape6";
startpos = versionString.indexOf(netscape6);
if (startpos > -1)
versionString = versionString.substring(startpos +
netscape6.length());
// Find first numeric in the string such as "MSIE 5.21;
Mac_PowerPC)"
startpos =
ERXStringUtilities.indexOfNumericInString(versionString);
if (startpos > -1) {
StringTokenizer st = new
StringTokenizer(versionString.substring(startpos), " ;");
if (st.hasMoreTokens())
version = st.nextToken(); // Will return "5.21"
portion of
// "5.21; Mac_PowerPC)"
}
// Test if we got a real number
try {
Double.parseDouble(version);
}
catch (NumberFormatException e) {
version = ERXBrowser.UNKNOWN_VERSION;
}
return version;
}
Any comments ?
Stefan
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden