File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
androidTest/java/org/wordpress/android/util
main/java/org/wordpress/android/util Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 22
33import android .test .InstrumentationTestCase ;
44
5+ import java .net .MalformedURLException ;
6+ import java .net .URL ;
57import java .util .HashMap ;
68import java .util .Map ;
79
@@ -75,4 +77,32 @@ public void testAppendUrlParameters2() {
7577 assertTrue ("failed test on url: " + url , false );
7678 }
7779 }
80+
81+ public void testHttps1 () {
82+ assertFalse (UrlUtils .isHttps (buildURL ("http://wordpress.com/xmlrpc.php" )));
83+ }
84+
85+ public void testHttps2 () {
86+ assertFalse (UrlUtils .isHttps (buildURL ("http://wordpress.com#.b.com/test" )));
87+ }
88+
89+ public void testHttps3 () {
90+ assertFalse (UrlUtils .isHttps (buildURL ("http://wordpress.com/xmlrpc.php" )));
91+ }
92+
93+ public void testHttps4 () {
94+ assertTrue (UrlUtils .isHttps (buildURL ("https://wordpress.com" )));
95+ }
96+
97+ public void testHttps5 () {
98+ assertTrue (UrlUtils .isHttps (buildURL ("https://wordpress.com/test#test" )));
99+ }
100+
101+ private URL buildURL (String address ) {
102+ URL url = null ;
103+ try {
104+ url = new URL (address );
105+ } catch (MalformedURLException e ) {}
106+ return url ;
107+ }
78108}
Original file line number Diff line number Diff line change 1010import java .io .UnsupportedEncodingException ;
1111import java .net .IDN ;
1212import java .net .URI ;
13+ import java .net .URL ;
1314import java .net .URLDecoder ;
1415import java .net .URLEncoder ;
1516import java .nio .charset .Charset ;
@@ -172,6 +173,17 @@ public static boolean isHttps(final String urlString) {
172173 return (urlString != null && urlString .startsWith ("https:" ));
173174 }
174175
176+ public static boolean isHttps (URL url ) {
177+ return url != null && "https" .equals (url .getProtocol ());
178+ }
179+
180+ public static boolean isHttps (URI uri ) {
181+ if (uri == null ) return false ;
182+
183+ String protocol = uri .getScheme ();
184+ return protocol != null && protocol .equals ("https" );
185+ }
186+
175187 /**
176188 * returns https: version of passed http: url
177189 */
You can’t perform that action at this time.
0 commit comments