Skip to content

Commit

Permalink
Fix encoding of clipboard binary
Browse files Browse the repository at this point in the history
When the RRF_WIDE is set, the data is in UTF-16. As all of the binary!s
for strings are in UTF-8, it needs to be converted to UTF-8, or the
script will not be able to convert it back to a string!.
  • Loading branch information
zsx committed Sep 14, 2015
1 parent 79cc241 commit 382c09e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/core/p-clipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@
len = req->actual;
if (GET_FLAG(req->flags, RRF_WIDE)) {
len /= sizeof(REBUNI); //correct length
// Copy the string (convert to latin-8 if it fits):
Set_Binary(arg, Copy_Wide_Str(req->data, len));

/* convert to UTF8, so that it can be converted back to string! */
REBCNT size = Length_As_UTF8((REBUNI*)req->data, len, TRUE, FALSE);
REBSER *ser = Make_Binary(size);
Encode_UTF8(SERIES_DATA(ser), size, req->data, &len, TRUE, FALSE);
SERIES_TAIL(ser) = len;
Set_Binary(arg, ser);
} else {
REBSER *ser = Make_Binary(len);
COPY_MEM(BIN_HEAD(ser), req->data, len);
Expand Down Expand Up @@ -92,8 +97,13 @@
len = req->actual;
if (GET_FLAG(req->flags, RRF_WIDE)) {
len /= sizeof(REBUNI); //correct length
// Copy the string (convert to latin-8 if it fits):
Set_Binary(arg, Copy_Wide_Str(req->data, len));

/* convert to UTF8, so that it can be converted back to string! */
REBCNT size = Length_As_UTF8((REBUNI*)req->data, len, TRUE, FALSE);
REBSER *ser = Make_Binary(size);
Encode_UTF8(SERIES_DATA(ser), size, req->data, &len, TRUE, FALSE);
SERIES_TAIL(ser) = len;
Set_Binary(arg, ser);
} else {
REBSER *ser = Make_Binary(len);
COPY_MEM(BIN_HEAD(ser), req->data, len);
Expand Down

0 comments on commit 382c09e

Please sign in to comment.