From ef384d9bc5980cf0d1e57be98e7829c7ebd90a1c Mon Sep 17 00:00:00 2001 From: HieuNT Date: Wed, 15 Apr 2015 13:21:14 +0700 Subject: [PATCH] Fix some bug regarding to 7bit mode Fix pdu size to text.lenght in 7bit mode pdu generating Eliminate null characters at the end of ascii string in 7bit mode pdu decoding --- pdu.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pdu.js b/pdu.js index 259f9fe..83da55b 100644 --- a/pdu.js +++ b/pdu.js @@ -183,8 +183,10 @@ pduParser.decode7Bit = function(code, count) { } var ascii = ''; - for(i in bin) + for(i in bin){ + if (parseInt(bin[i], 2) == 0) break; // terminate ascii string on null chanracter! ascii += String.fromCharCode(parseInt(bin[i], 2)); + } return ascii; } @@ -290,7 +292,10 @@ pduParser.generate = function(message) { } else if(message.encoding === '7bit') { user_data = pduParser.encode7Bit(text); - var size = user_data.length / 2; + // var size = user_data.length / 2; + var size = text.length; // the actual len + // console.log("sms.text %d: %s", text.length, text); + // console.log("sms.user_data %d: %s", user_data.length, user_data); } pdus[i] += ('00'+parseInt(size).toString(16)).slice(-2);