Skip to content

Commit 1691539

Browse files
authored
Merge pull request #46 from doroshsp/smtp_emoji_in_subject_issue
Extend _utf8Size function
2 parents 7010bf1 + 5ba909a commit 1691539

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

api/sendpulse.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,27 @@ function serialize(mixed_value) {
247247
l = str.length,
248248
code = '';
249249
for (i = 0; i < l; i++) {
250-
code = str.charCodeAt(i);
251-
if (code < 0x0080) {
252-
size += 1;
253-
} else if (code < 0x0800) {
254-
size += 2;
250+
code = str.charCodeAt(i);
251+
if (code < 0x0080) { //[0x0000, 0x007F]
252+
size += 1;
253+
} else if (code < 0x0800) { //[0x0080, 0x07FF]
254+
size += 2;
255+
} else if (code < 0xD800) { //[0x0800, 0xD7FF]
256+
size += 3;
257+
} else if (code < 0xDC00) { //[0xD800, 0xDBFF]
258+
var lo=str.charCodeAt(++i);
259+
if (i < l && lo >= 0xDC00 && lo <= 0xDFFF) { //followed by [0xDC00, 0xDFFF]
260+
size += 4;
255261
} else {
256-
size += 3;
262+
// UCS-2 String malformed
263+
size = 0
257264
}
265+
} else if (code < 0xE000) { //[0xDC00, 0xDFFF]
266+
// UCS-2 String malformed
267+
size = 0
268+
} else { //[0xE000, 0xFFFF]
269+
size += 3;
270+
}
258271
}
259272
return size;
260273
},

0 commit comments

Comments
 (0)