-
Notifications
You must be signed in to change notification settings - Fork 476
Issue #5376: Simpler method for determining whether a string is a search query #5384
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5384 +/- ##
===========================================
- Coverage 80.34% 80.2% -0.15%
+ Complexity 4241 4195 -46
===========================================
Files 547 537 -10
Lines 19267 19045 -222
Branches 2785 2765 -20
===========================================
- Hits 15481 15275 -206
+ Misses 2621 2609 -12
+ Partials 1165 1161 -4 Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave it up to a-c to do the final review. I would need more time to review this if I was the final reviewer (specifically, is the algorithm sufficient?) but for the general concept I'm leaning towards r+ once the unicode issue is addressed.
components/support/utils/src/main/java/mozilla/components/support/utils/URLStringUtils.kt
Outdated
Show resolved
Hide resolved
return uri.toString() | ||
} | ||
|
||
private val isURLLenient by lazy { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave this up to the lib owners but I think we should remove isURLLike
or at least have it share the isSearchTerm
impl because:
isURLLike
seems redundant toisSearchTerm
- What is
isURLLike
supposed to mean? Without further details, how are consumers supposed to use it confidently? Note that it doesn't look like our code uses it (query)
components/support/utils/src/main/java/mozilla/components/support/utils/URLStringUtils.kt
Outdated
Show resolved
Hide resolved
components/support/utils/src/main/java/mozilla/components/support/utils/URLStringUtils.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wfm but I'll hold off approving in favor of someone from a-c to review.
components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt
Show resolved
Hide resolved
components/support/utils/src/main/java/mozilla/components/support/utils/URLStringUtils.kt
Outdated
Show resolved
Hide resolved
components/support/utils/src/main/java/mozilla/components/support/utils/URLStringUtils.kt
Outdated
Show resolved
Hide resolved
} | ||
|
||
fun isSearchTerm(string: String) = !isURLLike(string, false) | ||
fun isSearchTerm(string: String) = !isURLLenient.matcher(string).matches() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably needs a changelog entry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, seems reasonable to me but waiting for a-c review.
components/support/utils/src/main/java/mozilla/components/support/utils/URLStringUtils.kt
Outdated
Show resolved
Hide resolved
components/support/utils/src/main/java/mozilla/components/support/utils/URLStringUtils.kt
Outdated
Show resolved
Hide resolved
components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt
Show resolved
Hide resolved
components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt
Show resolved
Hide resolved
components/support/utils/src/main/java/mozilla/components/support/utils/URLStringUtils.kt
Outdated
Show resolved
Hide resolved
Do not review this PR until further notice. There is a discrepancy in compiling regular expressions that work on the host (the developer's computer, that is) and that work on the device. |
Could we compile regex that work on device and, for now, not worry about those on the host? We could run our tests on device and not run the tests as unit tests. This assumes a-c has tests on device (which they should! 😄) |
Removing review request: I believe a-c will take it from here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Thanks, @hawkinsw.
…g is a URL From only one method to determine whether a string is a url, create two -- one for a strict check and one for a lenient check. The strict check will guarantee that the URL precisely conforms to ICANN standards (e.g., the TLD in the URL is valid). The lenient check will classify any string that contains ://, ., or : as a URL.
bors r+ |
Build succeeded
|
Update URLStringUtils.isSearchTerm to use a simpler method for
determining whether a string is a search query or a URL.
Pull Request checklist
After merge