fix(search): require .mao suffix in isValidMao to reduce search API c…#6415
Merged
Conversation
…alls
The previous regex only excluded whitespace and uppercase, so almost any
typed keyword (e.g. 'hello', 'abc', 'a') triggered the MAO user lookup API
and risked rate limiting / bans. Tighten isValidMao to match the MAO domain
pattern (^[^\sA-Z]{1,128}\.mao$) and reject pure-digit names, so the API
is only hit when the keyword actually looks like a MAO domain.
Contributor
There was a problem hiding this comment.
Pull request overview
Tightens MAO keyword validation to avoid triggering MAO user lookup for arbitrary search terms, reducing unnecessary network calls and potential rate limiting.
Changes:
- Updates
String?.isValidMao()to require a.maosuffix and match^[^\\sA-Z]{1,128}\\.mao$. - Adds an additional guard to reject digit-only MAO names before allowing the MAO lookup path.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (text.all { it.isDigit() }) return false | ||
| val regex = Regex("^[^\\sA-Z]{1,128}$") | ||
| return regex.matches(text) | ||
| val text = this.lowercase() |
Comment on lines
+827
to
+828
| val regex = Regex("^[^\\sA-Z]{1,128}\\.mao$") | ||
| if (!regex.matches(text)) return false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…alls
The previous regex only excluded whitespace and uppercase, so almost any typed keyword (e.g. 'hello', 'abc', 'a') triggered the MAO user lookup API and risked rate limiting / bans. Tighten isValidMao to match the MAO domain pattern (^[^\sA-Z]{1,128}.mao$) and reject pure-digit names, so the API is only hit when the keyword actually looks like a MAO domain.