Repository: wicket
Updated Branches:
  refs/heads/master 1fc5a627d -> c6d23d8eb


WICKET-6373 Edge not recognized in UserAgent

Fix detection of Chrome.
Add parsing in ClientProperties and WebClientInfo

(cherry picked from commit 4362848a7317b0c53d05be4b7542a670fa6b77d1)


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/c6d23d8e
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/c6d23d8e
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/c6d23d8e

Branch: refs/heads/master
Commit: c6d23d8ebb999d3cc8fa0676290f8dc554f34a9e
Parents: 1fc5a62
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Tue Jun 13 23:30:21 2017 +0200
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Tue Jun 13 23:31:44 2017 +0200

----------------------------------------------------------------------
 .../wicket/protocol/http/ClientProperties.java  | 22 +++++-
 .../wicket/protocol/http/request/UserAgent.java |  2 +-
 .../protocol/http/request/WebClientInfo.java    | 21 +++++-
 .../http/request/WebClientInfoTest.java         | 78 ++++++++++++++++++++
 4 files changed, 117 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/c6d23d8e/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java
 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java
index cd97e4f..fd162b0 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java
@@ -64,6 +64,7 @@ public class ClientProperties implements IClusterable
        private boolean browserOpera;
        private boolean browserSafari;
        private boolean browserChrome;
+       private boolean browserEdge;
        private int browserVersionMajor = -1;
        private int browserVersionMinor = -1;
        private int browserWidth = -1;
@@ -434,6 +435,15 @@ public class ClientProperties implements IClusterable
        {
                return browserChrome;
        }
+       /**
+        * Flag indicating that the browser is a derivative of the Microsoft 
Edge browser platform.
+        *
+        * @return True if a derivative of the Microsoft Edge browser platform.
+        */
+       public boolean isBrowserEdge()
+       {
+               return browserEdge;
+       }
 
        /**
         * 
@@ -545,6 +555,16 @@ public class ClientProperties implements IClusterable
        {
                this.browserChrome = browserChrome;
        }
+       /**
+        * Flag indicating that the browser is a derivative of the Microsoft 
Edge browser platform.
+        *
+        * @param browserEdge
+        *            True if a derivative of the Microsoft Edge browser 
platform.
+        */
+       public void setBrowserEdge(boolean browserEdge)
+       {
+               this.browserEdge = browserEdge;
+       }
 
        /**
         * @param browserVersionMajor
@@ -808,4 +828,4 @@ public class ClientProperties implements IClusterable
                
setBrowserHeight(parameters.getParameterValue("browserHeight").toInt(-1));
                
setHostname(parameters.getParameterValue("hostname").toString("N/A"));
        }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/c6d23d8e/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/UserAgent.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/UserAgent.java
 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/UserAgent.java
index b9d659c..e198166 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/UserAgent.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/UserAgent.java
@@ -38,7 +38,7 @@ enum UserAgent {
 
        OPERA(Arrays.asList("Opera")),
 
-       CHROME(Arrays.asList("Mozilla,Edge", "Chrome", "AppleWebKit", 
"Safari")),
+       CHROME("Edge", Arrays.asList("Mozilla", "Chrome", "AppleWebKit", 
"Safari")),
 
        SAFARI("Chrome,Edge", Arrays.asList("Mozilla", "AppleWebKit", 
"Safari")),
 

http://git-wip-us.apache.org/repos/asf/wicket/blob/c6d23d8e/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java
 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java
index 2b0747c..c0fb2a6 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java
@@ -198,12 +198,10 @@ public class WebClientInfo extends ClientInfo
                setMozillaProperties();
                setKonquerorProperties();
                setChromeProperties();
+               setEdgeProperties();
                setSafariProperties();
 
-               if (log.isDebugEnabled())
-               {
-                       log.debug("determined user agent: " + properties);
-               }
+               log.debug("determined user agent: {}", properties);
        }
 
        /**
@@ -236,6 +234,21 @@ public class WebClientInfo extends ClientInfo
        }
 
        /**
+        * sets the Edge specific properties
+        */
+       private void setEdgeProperties()
+       {
+               
properties.setBrowserEdge(UserAgent.EDGE.matches(getUserAgent()));
+
+               if (properties.isBrowserEdge())
+               {
+                       // e.g.: Mozilla/5.0 (Windows NT 10.0; Win64; x64) 
AppleWebKit/537.36 (KHTML, like Gecko)
+                       // Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063
+                       setMajorMinorVersionByPattern("edge/(\\d+)\\.(\\d+)");
+               }
+       }
+
+       /**
         * sets the safari specific properties
         */
        private void setSafariProperties()

http://git-wip-us.apache.org/repos/asf/wicket/blob/c6d23d8e/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java
 
b/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java
index eab2831..11a7db2 100644
--- 
a/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java
+++ 
b/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java
@@ -94,6 +94,8 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserSafari(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                                  is(equalTo(false)));
                }
        }
 
@@ -131,6 +133,8 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserSafari(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                                  is(equalTo(false)));
                }
        }
 
@@ -168,6 +172,8 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserSafari(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                                  is(equalTo(false)));
                }
        }
 
@@ -205,6 +211,8 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserSafari(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                                  is(equalTo(false)));
                }
        }
 
@@ -236,6 +244,7 @@ public class WebClientInfoTest
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserChrome(), is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserKonqueror(), is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserSafari(), is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(), is(equalTo(false)));
                }
        }
 
@@ -262,6 +271,7 @@ public class WebClientInfoTest
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserChrome(), is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserKonqueror(), is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserSafari(), is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(), is(equalTo(false)));
                }
        }
 
@@ -297,6 +307,8 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserInternetExplorer(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                               is(equalTo(false)));
                }
        }
 
@@ -334,6 +346,8 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserInternetExplorer(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                               is(equalTo(false)));
                }
        }
 
@@ -365,6 +379,8 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserInternetExplorer(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                               is(equalTo(false)));
                }
        }
 
@@ -400,6 +416,8 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserInternetExplorer(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                               is(equalTo(false)));
                }
        }
 
@@ -435,6 +453,8 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserInternetExplorer(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                               is(equalTo(false)));
                }
        }
 
@@ -471,6 +491,8 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserInternetExplorer(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                               is(equalTo(false)));
                }
        }
 
@@ -507,6 +529,8 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserInternetExplorer(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                               is(equalTo(false)));
                }
        }
 
@@ -542,6 +566,8 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserInternetExplorer(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                               is(equalTo(false)));
                }
        }
 
@@ -577,6 +603,8 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserInternetExplorer(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                               is(equalTo(false)));
                }
        }
 
@@ -612,6 +640,8 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserInternetExplorer(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                               is(equalTo(false)));
                }
        }
 
@@ -645,6 +675,8 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserInternetExplorer(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                               is(equalTo(false)));
                }
        }
 
@@ -681,6 +713,8 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserInternetExplorer(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                               is(equalTo(false)));
                }
        }
 
@@ -717,6 +751,8 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserInternetExplorer(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                               is(equalTo(false)));
                }
        }
 
@@ -753,6 +789,8 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserInternetExplorer(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                               is(equalTo(false)));
                }
        }
 
@@ -789,10 +827,50 @@ public class WebClientInfoTest
                                is(equalTo(false)));
                        assertThat(userAgent, 
webClientInfo.getProperties().isBrowserInternetExplorer(),
                                is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                               is(equalTo(false)));
                }
        }
 
        /**
+        * Test Microsoft Edge user-agent strings
+        */
+       @Test
+       public void edge15()
+       {
+               List<String> userAgents = Arrays.asList(
+                               "Mozilla/5.0 (Windows NT 10.0; Win64; x64) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 
Edge/15.15063");
+
+               for (String userAgent : userAgents)
+               {
+                       WebClientInfo webClientInfo = new 
WebClientInfo(requestCycleMock, userAgent);
+
+                       assertThat(userAgent, 
webClientInfo.getProperties().getBrowserVersionMajor(),
+                                  is(equalTo(15)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().getBrowserVersionMinor(),
+                                  is(equalTo(15063)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserMozillaFirefox(),
+                                  is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserMozilla(),
+                                  is(equalTo(false)));
+
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserOpera(),
+                                  is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserChrome(),
+                                  is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserKonqueror(),
+                                  is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserSafari(),
+                                  is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserInternetExplorer(),
+                                  is(equalTo(false)));
+                       assertThat(userAgent, 
webClientInfo.getProperties().isBrowserEdge(),
+                                  is(equalTo(true)));
+               }
+       }
+
+
+       /**
         * Test X-Forwarded-For ip address extraction.
         */
        @Test

Reply via email to