Fix crash on long-press when a placeholder is the only popup key#2619
Open
MiMoHo wants to merge 1 commit into
Open
Fix crash on long-press when a placeholder is the only popup key#2619MiMoHo wants to merge 1 commit into
MiMoHo wants to merge 1 commit into
Conversation
…ceholders A key with a placeholder as its only popup key (with popup key order containing only "layout") resulted in an empty but non-null popup key array, enabling long press that then crashes in PopupKeysKeyboard.Builder with a division by zero. fixes HeliBorg#1324 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Fixes #1324.
Problem
When a key has a
placeholderpopup as its only popup key, and the popup key order is set so that only "Layout" popups are used, long-pressing the key crashes the keyboard.Reproduction (from #1324):
{ "label": "ক", "popup": { "relevant": [ { "type": "placeholder" } ] } }Cause
createPopupKeysArrayproduces a non-empty array for the placeholder, but the placeholder resolves to an empty string. AfterPopupKeySpec.filterOutEmptyString(...)removes it, the result is an empty (but non-null) array.Key.KeyParamsthen still setsACTION_FLAGS_ENABLE_LONG_PRESS, so a long-press opens a popup keyboard with zero keys, which throws inPopupKeysKeyboard.Builder(division by / layout for zero columns).Fix
Only enable long-press / build
mPopupKeyswhen the filtered array is actually non-empty:This makes a placeholder-only popup set behave like "no popups", matching the expected behaviour described in the issue (long-press does nothing instead of crashing).
Tests
Added two tests to
ParserTest:placeholderAsOnlyPopup– a placeholder-only popup set yieldsmPopupKeys == nulland long-press disabled (this crashed before the fix).placeholderNextToOtherPopup– a placeholder alongside a real popup key keeps only the real key.All unit tests pass (
testRunTestsUnitTest).