Author: seade Date: Wed Nov 30 19:09:49 2005 New Revision: 350121 URL: http://svn.apache.org/viewcvs?rev=350121&view=rev Log: BrowserDetector was throwing an NPE for recent versions of Opera.
Added a test case. Added: jakarta/turbine/core/trunk/src/test/org/apache/turbine/util/BrowserDetectorTest.java (with props) Modified: jakarta/turbine/core/trunk/src/java/org/apache/turbine/util/BrowserDetector.java jakarta/turbine/core/trunk/xdocs/changes.xml Modified: jakarta/turbine/core/trunk/src/java/org/apache/turbine/util/BrowserDetector.java URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/trunk/src/java/org/apache/turbine/util/BrowserDetector.java?rev=350121&r1=350120&r2=350121&view=diff ============================================================================== --- jakarta/turbine/core/trunk/src/java/org/apache/turbine/util/BrowserDetector.java (original) +++ jakarta/turbine/core/trunk/src/java/org/apache/turbine/util/BrowserDetector.java Wed Nov 30 19:09:49 2005 @@ -232,10 +232,15 @@ // Modificaton by Chris Mospaw <[EMAIL PROTECTED]> if (userAgentString.indexOf(OPERA) != -1) { - //Ex: Mozilla/4.0 (Windows NT 4.0;US) Opera 3.61 [en] + // Ex: Mozilla/4.0 (Windows NT 4.0;US) Opera 3.61 [en] + // Ex: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.02 versionStartIndex = (userAgentString.indexOf(OPERA) + OPERA.length() + 1); versionEndIndex = userAgentString.indexOf(" ", versionStartIndex); + if (versionEndIndex == -1) + { + versionEndIndex = userAgentString.length(); + } browserName = OPERA; try Added: jakarta/turbine/core/trunk/src/test/org/apache/turbine/util/BrowserDetectorTest.java URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/trunk/src/test/org/apache/turbine/util/BrowserDetectorTest.java?rev=350121&view=auto ============================================================================== --- jakarta/turbine/core/trunk/src/test/org/apache/turbine/util/BrowserDetectorTest.java (added) +++ jakarta/turbine/core/trunk/src/test/org/apache/turbine/util/BrowserDetectorTest.java Wed Nov 30 19:09:49 2005 @@ -0,0 +1,73 @@ +package org.apache.turbine.util; + +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.turbine.test.BaseTestCase; + +/** + * Testing of the BrowserDetector class. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Scott Eade</a> + * @version $Id$ + */ +public class BrowserDetectorTest extends BaseTestCase +{ + public BrowserDetectorTest(String name) throws Exception + { + super(name); + } + + public void testFirefox() + { + String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5"; + BrowserDetector bd = new BrowserDetector(userAgent); + assertEquals(BrowserDetector.MOZILLA, bd.getBrowserName()); + // Should this really be 5? + assertEquals(5f, bd.getBrowserVersion(), 0.0f); + assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform()); + } + + public void testOpera() + { + String userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.02"; + BrowserDetector bd = new BrowserDetector(userAgent); + assertEquals(BrowserDetector.OPERA, bd.getBrowserName()); + assertEquals(8.02f, bd.getBrowserVersion(), 0.0f); + assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform()); + + userAgent = "Opera/7.51 (Windows NT 5.1; U) [en]"; + bd = new BrowserDetector(userAgent); + assertEquals(BrowserDetector.OPERA, bd.getBrowserName()); + assertEquals(7.51f, bd.getBrowserVersion(), 0.0f); + assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform()); + } + + public void testIE() + { + String userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; + BrowserDetector bd = new BrowserDetector(userAgent); + assertEquals(BrowserDetector.MSIE, bd.getBrowserName()); + assertEquals(6.0f, bd.getBrowserVersion(), 0.0f); + assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform()); + + userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"; + bd = new BrowserDetector(userAgent); + assertEquals(BrowserDetector.MSIE, bd.getBrowserName()); + assertEquals(6.0f, bd.getBrowserVersion(), 0.0f); + assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform()); + } +} Propchange: jakarta/turbine/core/trunk/src/test/org/apache/turbine/util/BrowserDetectorTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: jakarta/turbine/core/trunk/xdocs/changes.xml URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/trunk/xdocs/changes.xml?rev=350121&r1=350120&r2=350121&view=diff ============================================================================== --- jakarta/turbine/core/trunk/xdocs/changes.xml (original) +++ jakarta/turbine/core/trunk/xdocs/changes.xml Wed Nov 30 19:09:49 2005 @@ -24,8 +24,12 @@ <body> <release version="2.4-M2" date="in cvs"> + <action dev="seade" type="fix"> + BrowserDetector was throwing a NPE for recent versions of Opera - this + has been fixed. + </action> <action dev="sgoeschl" type="update"> - Setting all members of BaseServiceBroker to private as it should be. + Setting all members of BaseServiceBroker to private as it should be. </action> <action dev="sgoeschl" type="update"> Removed hack in Turbine.java forcing an early init of the AvalonComponentService. The --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]