Skip to content

Commit

Permalink
Handle quote input (#4762)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/414730916066338/1207180035648641/f

### Description
Addresses issue raised here:
#4472

### Steps to test this PR
- [x] Enter a URL in quotes (Or containing a quote)
- [x] Verify that the input is treated as a search term and not a URL

### UI changes
| Before  | After |
| ------ | ----- |

![ddg](https://github.com/user-attachments/assets/4ce49027-1c42-4747-af95-15f27d0a97e0)|![ddg_after](https://github.com/user-attachments/assets/70cbda19-7812-46bf-aeb5-a33fc0b9d7eb)
  • Loading branch information
joshliebe authored Jul 19, 2024
1 parent ed47148 commit 2572ea7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
42 changes: 41 additions & 1 deletion app/src/test/java/com/duckduckgo/app/global/UriStringTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 2572ea7

Please sign in to comment.