From f581ee7b1e934690ed634ed2610bc19472ba6ff9 Mon Sep 17 00:00:00 2001 From: Aram Date: Tue, 10 Dec 2024 13:35:10 +0100 Subject: [PATCH] Updated the isValidURL to allow all types of URL, not only the www. --- .../main/java/software/bluelib/utils/math/MiscUtils.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/software/bluelib/utils/math/MiscUtils.java b/common/src/main/java/software/bluelib/utils/math/MiscUtils.java index 7b5f5c3d..1473fa02 100644 --- a/common/src/main/java/software/bluelib/utils/math/MiscUtils.java +++ b/common/src/main/java/software/bluelib/utils/math/MiscUtils.java @@ -56,17 +56,18 @@ private MiscUtils() {} */ public static boolean isValidURL(String pUrl) { try { - if (pUrl.startsWith("www.")) { + if (!pUrl.startsWith("http://") && !pUrl.startsWith("https://")) { pUrl = "https://" + pUrl; } - java.net.URI uri = new java.net.URI(pUrl); - return uri.isAbsolute() && (uri.getScheme().equals("http") || uri.getScheme().equals("https")); + java.net.URI uri = new java.net.URI(pUrl); + return uri.isAbsolute() && ("http".equals(uri.getScheme()) || "https".equals(uri.getScheme())); } catch (Exception pException) { return false; } } + /** * A {@link Boolean} that checks if a string is a valid email address. *