Merge pull request #4668 from wwylele/swkbd-size

applet/swkbd: use UTF-16 string to test string size
This commit is contained in:
Weiyi Wang 2019-03-05 12:23:54 -05:00 committed by GitHub
commit d0de727a97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -52,8 +52,10 @@ ValidationError SoftwareKeyboard::ValidateInput(const std::string& input) const
return error; return error;
} }
// TODO(jroweboy): Is max_text_length inclusive or exclusive? // 3DS uses UTF-16 string to test string size
if (input.size() > config.max_text_length) { std::u16string u16input = Common::UTF8ToUTF16(input);
if (u16input.size() > config.max_text_length) {
return ValidationError::MaxLengthExceeded; return ValidationError::MaxLengthExceeded;
} }
@ -62,7 +64,7 @@ ValidationError SoftwareKeyboard::ValidateInput(const std::string& input) const
bool is_empty = input.empty(); bool is_empty = input.empty();
switch (config.accept_mode) { switch (config.accept_mode) {
case AcceptedInput::FixedLength: case AcceptedInput::FixedLength:
if (input.size() != config.max_text_length) { if (u16input.size() != config.max_text_length) {
return ValidationError::FixedLengthRequired; return ValidationError::FixedLengthRequired;
} }
break; break;