diff --git a/app/src/test/java/com/duckduckgo/app/global/UriStringTest.kt b/app/src/test/java/com/duckduckgo/app/global/UriStringTest.kt index 7f03fb5f0f4e..6f372c226870 100644 --- a/app/src/test/java/com/duckduckgo/app/global/UriStringTest.kt +++ b/app/src/test/java/com/duckduckgo/app/global/UriStringTest.kt @@ -391,7 +391,47 @@ class UriStringTest { } @Test - fun whenSchemeIsValidFtpButNotHttpThenNot() { + fun whenSchemeIsValidFtpButNotHttpThenIsFalse() { assertFalse(isWebUrl("ftp://example.com")) } + + @Test + fun whenUrlStartsWithDoubleQuoteThenIsFalse() { + assertFalse(isWebUrl("\"example.com")) + } + + @Test + fun whenUrlStartsWithSingleQuoteThenIsFalse() { + assertFalse(isWebUrl("'example.com")) + } + + @Test + fun whenUrlEndsWithDoubleQuoteThenIsFalse() { + assertFalse(isWebUrl("example.com\"")) + } + + @Test + fun whenUrlEndsWithSingleQuoteThenIsFalse() { + assertFalse(isWebUrl("example.com'")) + } + + @Test + fun whenUrlStartsAndEndsWithDoubleQuoteThenIsFalse() { + assertFalse(isWebUrl("\"example.com\"")) + } + + @Test + fun whenUrlStartsAndEndsWithSingleQuoteThenIsFalse() { + assertFalse(isWebUrl("'example.com'")) + } + + @Test + fun whenUrlContainsDoubleQuoteThenIsFalse() { + assertFalse(isWebUrl("example\".com")) + } + + @Test + fun whenUrlContainsSingleQuoteThenIsFalse() { + assertFalse(isWebUrl("example'.com")) + } } diff --git a/browser-api/src/main/java/com/duckduckgo/app/browser/UriString.kt b/browser-api/src/main/java/com/duckduckgo/app/browser/UriString.kt index a7a07622db59..5ea796d18034 100644 --- a/browser-api/src/main/java/com/duckduckgo/app/browser/UriString.kt +++ b/browser-api/src/main/java/com/duckduckgo/app/browser/UriString.kt @@ -96,6 +96,9 @@ class UriString { } fun isWebUrl(inputQuery: String): Boolean { + if (inputQuery.contains("\"") || inputQuery.contains("'")) { + return false + } if (inputQuery.contains(space)) return false val rawUri = Uri.parse(inputQuery)