Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SES1251 - App crash on non alphanumeric RE-FIX #1445

Merged

Conversation

AL-Session
Copy link
Collaborator

Contributor checklist

  • I have tested my contribution on these devices:
  • Virtual device W, Pixel 3a on Android 9 / API 28
  • Virtual device X, Pixel 3a on Android 14 / API 34
  • My contribution is fully baked and ready to be merged as is
  • I ensure that all the open issues my contribution fixes are mentioned in the commit message of my first commit using the Fixes #1234 syntax

Description

Searching messages and entering a non-alphanumeric character as the first character caused an crash & restart. This was due to the search being performed after each character entered, and any illegal character entered as the 1st character is replaced with a space - so in effect we are searching on the string " " which was causing the error.

Guards have been put in place to prevent search queries on strings of " " which eliminates the error.

Tested by entering a variety of non-alphanumeric characters as first search letter of message search both in regular user-to-user comms & in a group- all fine now.

import java.io.IOException
import java.util.Locale

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert file?

Do you have a formatter that's adding linebreaks between import groups.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, I just tend to prefer lines between import groups, but I can revert :) / Done

@@ -41,14 +48,19 @@ class GlobalSearchViewModel @Inject constructor(private val searchRepository: Se
_queryText
.buffer(onBufferOverflow = BufferOverflow.DROP_OLDEST)
.mapLatest { query ->
// Minimum search term is 2 characters

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS lets us search 1 character.

It's not necessarily a good search, but you can give yourself a 1-char name, so you should be able to search that... and ideally a match of an entire word should be elevated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, fair enough - have allowed 1 char searches and it does prioritise contacts & groups over individual messages.

val settableFuture = SettableFuture<SearchResult>()

// If we already have a search running then stop it
if (!settableFuture.isDone) { settableFuture.cancel(true) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to check if the Future done, it's checked in cancel, the comment is not exactly true, as canceling this future would essentially stop listening for results, but won't stop any work being done.

Is it even necessary? mapLatest will prevent stale results clobbering newer ones.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I didn't know mapLatest did that - have reverted settableFuture back to being a val defined at point of use

if (TextUtils.isEmpty(query)) {
// If the sanitized search query is empty or less than 2 chars then abort the search
String cleanQuery = sanitizeQuery(query).trim();
if (cleanQuery.isEmpty() || cleanQuery.length() < 2) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit tautological, length < 2 would cover both cases, but maybe the isEmpty is preferred?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted so only using sanitize -> trim -> isEmpty

Copy link

@bemusementpark bemusementpark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@bemusementpark bemusementpark merged commit 0e7a981 into oxen-io:dev Apr 24, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants