From 7128f8f5f01aa75b82f4b34262416041105a0c3e Mon Sep 17 00:00:00 2001
From: SerhiiGadzhilov <71632867+SerhiiGadzhilov@users.noreply.github.com>
Date: Wed, 27 Jan 2021 21:38:52 +0200
Subject: [PATCH] Fixed #6839 Wrong text encoding in iMessage (#6927)
* Fixed #6839 Wrong text encoding in iMessage
* Update ChangeLog
---
ChangeLog | 1 +
src/lib/platform/OSXClipboard.cpp | 24 +++++++------
.../platform/OSXClipboardUTF8Converter.cpp | 19 +++++++++++
src/lib/platform/OSXClipboardUTF8Converter.h | 30 ++++++++++++++++
.../OSXClipboardUTF8ConverterTest.cpp | 34 +++++++++++++++++++
5 files changed, 97 insertions(+), 11 deletions(-)
create mode 100644 src/lib/platform/OSXClipboardUTF8Converter.cpp
create mode 100644 src/lib/platform/OSXClipboardUTF8Converter.h
create mode 100644 src/test/unittests/platform/OSXClipboardUTF8ConverterTest.cpp
diff --git a/ChangeLog b/ChangeLog
index 965d6cd5e..12700031f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,7 @@ Bug fixes:
- #6920 Windows Installer checksums
- #6921 Handling pre-main window creation status notifications
- #6922 macOS CI build
+- #6927 Text copied and pasted between Windows and Mac OS converts to japanese
Enhancements:
- #6912 Removes UI for Screen Saver Sync and Files Drag and Drop
diff --git a/src/lib/platform/OSXClipboard.cpp b/src/lib/platform/OSXClipboard.cpp
index 7212175c7..bfec7cdd4 100644
--- a/src/lib/platform/OSXClipboard.cpp
+++ b/src/lib/platform/OSXClipboard.cpp
@@ -19,6 +19,7 @@
#include "platform/OSXClipboard.h"
#include "synergy/Clipboard.h"
+#include "platform/OSXClipboardUTF8Converter.h"
#include "platform/OSXClipboardUTF16Converter.h"
#include "platform/OSXClipboardTextConverter.h"
#include "platform/OSXClipboardBMPConverter.h"
@@ -36,11 +37,10 @@ OSXClipboard::OSXClipboard() :
{
m_converters.push_back(new OSXClipboardHTMLConverter);
m_converters.push_back(new OSXClipboardBMPConverter);
+ m_converters.push_back(new OSXClipboardUTF8Converter);
m_converters.push_back(new OSXClipboardUTF16Converter);
m_converters.push_back(new OSXClipboardTextConverter);
-
-
OSStatus createErr = PasteboardCreate(kPasteboardClipboard, &m_pboard);
if (createErr != noErr) {
LOG((CLOG_DEBUG "failed to create clipboard reference: error %i", createErr));
@@ -121,16 +121,18 @@ OSXClipboard::add(EFormat format, const String & data)
CFDataRef dataRef = CFDataCreate(kCFAllocatorDefault, (UInt8 *)osXData.data(), osXData.size());
PasteboardItemID itemID = 0;
- PasteboardPutItemFlavor(
- m_pboard,
- itemID,
- flavorType,
- dataRef,
- kPasteboardFlavorNoFlags);
-
- LOG((CLOG_DEBUG "added %d bytes to clipboard format: %d", data.size(), format));
+ if (dataRef) {
+ PasteboardPutItemFlavor(
+ m_pboard,
+ itemID,
+ flavorType,
+ dataRef,
+ kPasteboardFlavorNoFlags);
+
+ CFRelease(dataRef);
+ LOG((CLOG_DEBUG "added %d bytes to clipboard format: %d", data.size(), format));
+ }
}
-
}
}
diff --git a/src/lib/platform/OSXClipboardUTF8Converter.cpp b/src/lib/platform/OSXClipboardUTF8Converter.cpp
new file mode 100644
index 000000000..ca6f5684a
--- /dev/null
+++ b/src/lib/platform/OSXClipboardUTF8Converter.cpp
@@ -0,0 +1,19 @@
+#include "OSXClipboardUTF8Converter.h"
+
+CFStringRef
+OSXClipboardUTF8Converter::getOSXFormat() const
+{
+ return CFSTR("public.utf8-plain-text");
+}
+
+String
+OSXClipboardUTF8Converter::doFromIClipboard(const String& data) const
+{
+ return data;
+}
+
+String
+OSXClipboardUTF8Converter::doToIClipboard(const String& data) const
+{
+ return data;
+}
diff --git a/src/lib/platform/OSXClipboardUTF8Converter.h b/src/lib/platform/OSXClipboardUTF8Converter.h
new file mode 100644
index 000000000..29e0a8a3f
--- /dev/null
+++ b/src/lib/platform/OSXClipboardUTF8Converter.h
@@ -0,0 +1,30 @@
+/*
+ * synergy -- mouse and keyboard sharing utility
+ * Copyright (C) 2012-2016 Symless Ltd.
+ * Copyright (C) 2004 Chris Schoeneman
+ *
+ * This package is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * found in the file LICENSE that should have accompanied this file.
+ *
+ * This package is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+#pragma once
+
+#include "platform/OSXClipboardAnyTextConverter.h"
+
+class OSXClipboardUTF8Converter : public OSXClipboardAnyTextConverter
+{
+public:
+ virtual CFStringRef getOSXFormat() const;
+private:
+ virtual String doFromIClipboard(const String&) const;
+ virtual String doToIClipboard(const String&) const;
+};
+
diff --git a/src/test/unittests/platform/OSXClipboardUTF8ConverterTest.cpp b/src/test/unittests/platform/OSXClipboardUTF8ConverterTest.cpp
new file mode 100644
index 000000000..941daae42
--- /dev/null
+++ b/src/test/unittests/platform/OSXClipboardUTF8ConverterTest.cpp
@@ -0,0 +1,34 @@
+/*
+ * synergy -- mouse and keyboard sharing utility
+ * Copyright (C) 2012-2016 Symless Ltd.
+ * Copyright (C) 2011 Nick Bolton
+ *
+ * This package is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * found in the file LICENSE that should have accompanied this file.
+ *
+ * This package is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "platform/OSXClipboardUTF8Converter.h"
+#include "test/global/gtest.h"
+
+TEST(OSXClipboardUTF8ConverterTests, test_Format)
+{
+ OSXClipboardUTF8Converter converter;
+ EXPECT_EQ(IClipboard::kText, converter.getFormat());
+ EXPECT_EQ(CFSTR("public.utf8-plain-text"), converter.getOSXFormat());
+}
+
+TEST(OSXClipboardUTF8ConverterTests, test_readWriteClipboard)
+{
+ OSXClipboardUTF8Converter converter;
+ EXPECT_EQ("test data\r", converter.fromIClipboard("test data\n"));
+ EXPECT_EQ("test data\n", converter.toIClipboard("test data\r"));
+}