Skip to content

Commit 7dd3657

Browse files
authored
fix: clipboard.readBuffer returning empty value (electron#24454)
1 parent e59370f commit 7dd3657

File tree

2 files changed

+4
-25
lines changed

2 files changed

+4
-25
lines changed

shell/common/api/electron_api_clipboard.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ void Clipboard::WriteBuffer(const std::string& format,
7171
base::span<const uint8_t> payload_span(
7272
reinterpret_cast<const uint8_t*>(node::Buffer::Data(buffer)),
7373
node::Buffer::Length(buffer));
74-
writer.WriteData(
75-
base::UTF8ToUTF16(ui::ClipboardFormatType::GetType(format).Serialize()),
76-
mojo_base::BigBuffer(payload_span));
74+
writer.WriteData(base::UTF8ToUTF16(format),
75+
mojo_base::BigBuffer(payload_span));
7776
}
7877

7978
void Clipboard::Write(const gin_helper::Dictionary& data,

spec/api-clipboard-spec.js

+2-22
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,11 @@ describe('clipboard module', () => {
112112
});
113113
});
114114

115-
describe('clipboard.writeBuffer(format, buffer)', () => {
115+
describe('clipboard.readBuffer(format)', () => {
116116
it('writes a Buffer for the specified format', function () {
117-
if (process.platform !== 'darwin') {
118-
// FIXME(alexeykuzmin): Skip the test.
119-
// this.skip()
120-
return;
121-
}
122-
123117
const buffer = Buffer.from('writeBuffer', 'utf8');
124118
clipboard.writeBuffer('public.utf8-plain-text', buffer);
125-
expect(clipboard.readText()).to.equal('writeBuffer');
119+
expect(buffer.equals(clipboard.readBuffer('public.utf8-plain-text'))).to.equal(true);
126120
});
127121

128122
it('throws an error when a non-Buffer is specified', () => {
@@ -131,18 +125,4 @@ describe('clipboard module', () => {
131125
}).to.throw(/buffer must be a node Buffer/);
132126
});
133127
});
134-
135-
describe('clipboard.readBuffer(format)', () => {
136-
before(function () {
137-
if (process.platform !== 'darwin') {
138-
this.skip();
139-
}
140-
});
141-
142-
it('returns a Buffer of the content for the specified format', () => {
143-
const buffer = Buffer.from('this is binary', 'utf8');
144-
clipboard.writeText(buffer.toString());
145-
expect(buffer.equals(clipboard.readBuffer('public.utf8-plain-text'))).to.equal(true);
146-
});
147-
});
148128
});

0 commit comments

Comments
 (0)