diff --git a/engine/src/flutter/shell/platform/windows/platform_handler.cc b/engine/src/flutter/shell/platform/windows/platform_handler.cc index 605094bdf2..4c54b3d4cf 100644 --- a/engine/src/flutter/shell/platform/windows/platform_handler.cc +++ b/engine/src/flutter/shell/platform/windows/platform_handler.cc @@ -369,6 +369,10 @@ void PlatformHandler::HandleMethodCall( result->Error(kClipboardError, kUnknownClipboardFormatMessage); return; } + if (!itr->value.IsString()) { + result->Error(kClipboardError, kUnknownClipboardFormatMessage); + return; + } SetPlainText(itr->value.GetString(), std::move(result)); } else if (method.compare(kPlaySoundMethod) == 0) { // Only one string argument is expected. diff --git a/engine/src/flutter/shell/platform/windows/platform_handler_unittests.cc b/engine/src/flutter/shell/platform/windows/platform_handler_unittests.cc index 2ae025b464..71f383ae73 100644 --- a/engine/src/flutter/shell/platform/windows/platform_handler_unittests.cc +++ b/engine/src/flutter/shell/platform/windows/platform_handler_unittests.cc @@ -37,6 +37,8 @@ static constexpr char kClipboardHasStringsFakeContentTypeMessage[] = "{\"method\":\"Clipboard.hasStrings\",\"args\":\"text/madeupcontenttype\"}"; static constexpr char kClipboardSetDataMessage[] = "{\"method\":\"Clipboard.setData\",\"args\":{\"text\":\"hello\"}}"; +static constexpr char kClipboardSetDataNullTextMessage[] = + "{\"method\":\"Clipboard.setData\",\"args\":{\"text\":null}}"; static constexpr char kClipboardSetDataUnknownTypeMessage[] = "{\"method\":\"Clipboard.setData\",\"args\":{\"madeuptype\":\"hello\"}}"; static constexpr char kSystemSoundTypeAlertMessage[] = @@ -368,6 +370,19 @@ TEST_F(PlatformHandlerTest, ClipboardSetData) { EXPECT_EQ(result, "[null]"); } +// Regression test for: https://github.com/flutter/flutter/issues/121976 +TEST_F(PlatformHandlerTest, ClipboardSetDataTextMustBeString) { + use_engine_with_view(); + + TestBinaryMessenger messenger; + PlatformHandler platform_handler(&messenger, engine()); + + std::string result = + SimulatePlatformMessage(&messenger, kClipboardSetDataNullTextMessage); + + EXPECT_EQ(result, "[\"Clipboard error\",\"Unknown clipboard format\",null]"); +} + TEST_F(PlatformHandlerTest, ClipboardSetDataUnknownType) { use_engine_with_view();