fix utf7 encoding with emoji (#2564)
This commit is contained in:
@@ -75,9 +75,7 @@ pub fn utf7_encode(text: &str) -> String {
|
|||||||
let mut bits = 0;
|
let mut bits = 0;
|
||||||
let mut u: u32 = 0;
|
let mut u: u32 = 0;
|
||||||
|
|
||||||
for ch_ in text.chars() {
|
for ch in text.encode_utf16() {
|
||||||
let ch = ch_ as u16;
|
|
||||||
|
|
||||||
if (0x20..0x7f).contains(&ch) {
|
if (0x20..0x7f).contains(&ch) {
|
||||||
if shifted {
|
if shifted {
|
||||||
if bits > 0 {
|
if bits > 0 {
|
||||||
@@ -91,7 +89,7 @@ pub fn utf7_encode(text: &str) -> String {
|
|||||||
if ch == 0x26 {
|
if ch == 0x26 {
|
||||||
result.push_str("&-");
|
result.push_str("&-");
|
||||||
} else {
|
} else {
|
||||||
result.push(ch_);
|
result.push((ch as u8) as char);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if !shifted {
|
if !shifted {
|
||||||
@@ -178,6 +176,7 @@ mod tests {
|
|||||||
("&ZeVnLIqe-", "日本語"),
|
("&ZeVnLIqe-", "日本語"),
|
||||||
("Item 3 is &AKM-1.", "Item 3 is £1."),
|
("Item 3 is &AKM-1.", "Item 3 is £1."),
|
||||||
("Plus minus &- -&- &--", "Plus minus & -& &-"),
|
("Plus minus &- -&- &--", "Plus minus & -& &-"),
|
||||||
|
("&VMhUyNg93gQ-", "哈哈😄"),
|
||||||
] {
|
] {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
super::utf7_encode(input),
|
super::utf7_encode(input),
|
||||||
|
|||||||
Reference in New Issue
Block a user