diff options
author | Henri Sara <henri.sara@itmill.com> | 2010-04-07 10:59:53 +0000 |
---|---|---|
committer | Henri Sara <henri.sara@itmill.com> | 2010-04-07 10:59:53 +0000 |
commit | 4ab7fb8755a8825c05c349b3612e02ba2f9815ea (patch) | |
tree | fdedc69a9a9b0bd30b1746cfca8385e463a413dc /src | |
parent | 85f778b0f7c05ca2f20885bcc1ada2aa4753e8c0 (diff) | |
download | vaadin-framework-4ab7fb8755a8825c05c349b3612e02ba2f9815ea.tar.gz vaadin-framework-4ab7fb8755a8825c05c349b3612e02ba2f9815ea.zip |
#4491 safer browser version detection
svn changeset:12352/svn branch:6.3
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/VBrowserDetails.java | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/VBrowserDetails.java b/src/com/vaadin/terminal/gwt/client/VBrowserDetails.java index ea2a709830..49eda4c072 100644 --- a/src/com/vaadin/terminal/gwt/client/VBrowserDetails.java +++ b/src/com/vaadin/terminal/gwt/client/VBrowserDetails.java @@ -67,18 +67,18 @@ public class VBrowserDetails implements Serializable { if (isIE) {
String ieVersionString = userAgent.substring(userAgent
.indexOf("msie ") + 5);
- ieVersionString = ieVersionString.substring(0, ieVersionString
+ ieVersionString = safeSubstring(ieVersionString, 0, ieVersionString
.indexOf(";"));
parseVersionString(ieVersionString);
} else if (isFirefox) {
int i = userAgent.indexOf(" firefox/") + 9;
- parseVersionString(userAgent.substring(i, i + 5));
+ parseVersionString(safeSubstring(userAgent, i, i + 5));
} else if (isChrome) {
int i = userAgent.indexOf(" chrome/") + 8;
- parseVersionString(userAgent.substring(i, i + 5));
+ parseVersionString(safeSubstring(userAgent, i, i + 5));
} else if (isSafari) {
int i = userAgent.indexOf(" version/") + 9;
- parseVersionString(userAgent.substring(i, i + 5));
+ parseVersionString(safeSubstring(userAgent, i, i + 5));
} else if (isOpera) {
int i = userAgent.indexOf(" version/");
if (i != -1) {
@@ -87,26 +87,41 @@ public class VBrowserDetails implements Serializable { } else {
i = userAgent.indexOf("opera/") + 6;
}
- parseVersionString(userAgent.substring(i, i + 5));
+ parseVersionString(safeSubstring(userAgent, i, i + 5));
}
}
private void parseVersionString(String versionString) {
int idx = versionString.indexOf('.');
+ if (idx < 0) {
+ idx = versionString.length();
+ }
+ browserMajorVersion = Integer.parseInt(safeSubstring(versionString, 0,
+ idx));
+
int idx2 = versionString.indexOf('.', idx + 1);
if (idx2 < 0) {
idx2 = versionString.length();
}
- browserMajorVersion = Integer.parseInt(versionString.substring(0, idx));
try {
- browserMinorVersion = Integer.parseInt(versionString.substring(
+ browserMinorVersion = Integer.parseInt(safeSubstring(versionString,
idx + 1, idx2).replaceAll("[^0-9].*", ""));
} catch (NumberFormatException e) {
// leave the minor version unmodified (-1 = unknown)
}
}
+ private String safeSubstring(String string, int beginIndex, int endIndex) {
+ if (beginIndex < 0) {
+ beginIndex = 0;
+ }
+ if (endIndex < 0) {
+ endIndex = string.length();
+ }
+ return string.substring(beginIndex, endIndex);
+ }
+
/**
* Tests if the browser is Firefox.
*
|