Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/utf7.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ transform_utf16_utf7 (RECODE_SUBTASK subtask)
if (!recode_get_ucs2 (&value, subtask))
SUBTASK_RETURN (subtask);
}
else if (value == '+')
{
/* A plus sign is simply written as "+-". */

recode_put_byte ('+', subtask);
recode_put_byte ('-', subtask);
if (!recode_get_ucs2 (&value, subtask))
SUBTASK_RETURN (subtask);
}
else
{
/* Copy a string of non-direct characters. */
Expand Down Expand Up @@ -162,6 +171,13 @@ transform_utf7_utf16 (RECODE_SUBTASK subtask)
if (character == '+')
{
character = recode_get_byte (subtask);
if (character == '-')
{
/* "+-" is the encoding of a plus sign itself. */
recode_put_ucs2 ('+', subtask);
character = recode_get_byte (subtask);
continue;
}
while (IS_BASE64 (character))
{
/* Process first byte of first quadruplet. */
Expand Down
5 changes: 4 additions & 1 deletion tests/t40_utf7.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'Hi Mom +Jjo!\n',
'+ZeVnLIqe\n',
'Item 3 is +AKM-1.\n',
'1 +- 1 = 2\n',
]

outputs = [
Expand All @@ -17,7 +18,9 @@
'0x263A, 0x0021, 0x000A\n'),
'0xFEFF, 0x65E5, 0x672C, 0x8A9E, 0x000A\n',
('0xFEFF, 0x0049, 0x0074, 0x0065, 0x006D, 0x0020, 0x0033, 0x0020,\n'
'0x0069, 0x0073, 0x0020, 0x00A3, 0x0031, 0x002E, 0x000A\n')]
'0x0069, 0x0073, 0x0020, 0x00A3, 0x0031, 0x002E, 0x000A\n'),
('0xFEFF, 0x0031, 0x0020, 0x002B, 0x0020, 0x0031, 0x0020, 0x003D,\n'
'0x0020, 0x0032, 0x000A\n')]

class Test:

Expand Down