summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/UrlUtils.java
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2011-08-10 18:16:52 -0700
committerJohn Reck <jreck@google.com>2011-08-11 11:37:45 -0700
commit434e9f83e13c0758dcdefe214357fc9cc9f104d5 (patch)
tree71a6a98e0c677b8e6ce00a267cf449074b1fa746 /src/com/android/browser/UrlUtils.java
parente3da7d615be4710da92a79e6ed70dc1982deda4c (diff)
downloadpackages_apps_Browser-434e9f83e13c0758dcdefe214357fc9cc9f104d5.tar.gz
packages_apps_Browser-434e9f83e13c0758dcdefe214357fc9cc9f104d5.tar.bz2
packages_apps_Browser-434e9f83e13c0758dcdefe214357fc9cc9f104d5.zip
Strip http://(www.)? from url input
Bug: 4982126 Change-Id: Ia8a9ade2ad4f578e40333f42e02edc161f7fa1c2
Diffstat (limited to 'src/com/android/browser/UrlUtils.java')
-rw-r--r--src/com/android/browser/UrlUtils.java15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/com/android/browser/UrlUtils.java b/src/com/android/browser/UrlUtils.java
index c922e55f5..681b24248 100644
--- a/src/com/android/browser/UrlUtils.java
+++ b/src/com/android/browser/UrlUtils.java
@@ -40,28 +40,29 @@ public class UrlUtils {
private final static String QUICKSEARCH_G = "http://www.google.com/m?q=%s";
private final static String QUERY_PLACE_HOLDER = "%s";
- // Regular expression which matches http://, followed by some stuff, followed by
- // optionally a trailing slash, all matched as separate groups.
- private static final Pattern STRIP_URL_PATTERN = Pattern.compile("^(http://)(.*?)(/$)?");
+ // Regular expression to strip http://, optionally www., and optionally
+ // the trailing slash
+ private static final Pattern STRIP_URL_PATTERN =
+ Pattern.compile("^http://(?:www\\.)?(.*?)/?$");
private UrlUtils() { /* cannot be instantiated */ }
/**
- * Strips the provided url of preceding "http://" and any trailing "/". Does not
+ * Strips the provided url of preceding "http://", "www.", and any trailing "/". Does not
* strip "https://". If the provided string cannot be stripped, the original string
* is returned.
*
* TODO: Put this in TextUtils to be used by other packages doing something similar.
*
* @param url a url to strip, like "http://www.google.com/"
- * @return a stripped url like "www.google.com", or the original string if it could
+ * @return a stripped url like "google.com", or the original string if it could
* not be stripped
*/
public static String stripUrl(String url) {
if (url == null) return null;
Matcher m = STRIP_URL_PATTERN.matcher(url);
- if (m.matches() && m.groupCount() == 3) {
- return m.group(2);
+ if (m.matches()) {
+ return m.group(1);
} else {
return url;
}