diff --git a/src/core/lib/Gsm7.mjs b/src/core/lib/Gsm7.mjs index bdcd493e..bed2220d 100644 --- a/src/core/lib/Gsm7.mjs +++ b/src/core/lib/Gsm7.mjs @@ -582,12 +582,9 @@ function convertCharTable(chars) { for (let i=0; i<128; i++) { let char = chars[~~(i/16) + (i%16)*8]; if (char in specials) { - //console.log("<", char, "*", specials[char], "*", specials, ">\n"); char = specials[char]; } - //console.log("<", i, ~~(i/16), (i%16), ~~(i/16) + (i%16)*8, char, ">\n", chars, "------------------"); if (char.length == 4) { - //console.log("\\u" + char); char = String.fromCodePoint(Number("0x" + char)); } conv[i] = char; @@ -634,8 +631,8 @@ export function toGsm7(text, charset, extension, CRpad) { if (c==-1) { c = extension.indexOf(char); if (c==-1) { - throw "character '" + char + "' is not present in current charset+extension." + - "A real device would encode this SMS using UCS-2 (UTF-16)"; + throw new OperationError("character '" + char + "' is not present in current charset+extension.
" + + "A real device would encode this SMS using UCS-2 (UTF-16)"); } codePoints.push(0x1b); } @@ -644,8 +641,8 @@ export function toGsm7(text, charset, extension, CRpad) { // optional step #2: final CR to cope with unexpected encoding of 0x00 or to affirm a wanted final CR if (CRpad) { - if ((codePoints.length % 8 == 7) || ((codePoints.length % 8 == 0) && codePoints[-1] == 0x0d)) { - codePoints.push(0x0d); + if ((codePoints.length % 8 == 7) || ((codePoints.length % 8 == 0) && codePoints[codePoints.length-1] == 13)) { + codePoints.push(13); } } @@ -706,7 +703,7 @@ export function fromGsm7(sms, charset, extension, CRpad) { // optional step #2: remove final CR when on octet boundary if (CRpad) { - if ((codePoints.length % 8 == 0) && codePoints[-1] == 0x0d) { + if ((codePoints.length % 8 == 0) && codePoints[codePoints.length-1] == 13) { codePoints.pop(); } } diff --git a/tests/node/index.mjs b/tests/node/index.mjs index 4a696185..f6abba40 100644 --- a/tests/node/index.mjs +++ b/tests/node/index.mjs @@ -16,13 +16,13 @@ import { } from "../lib/utils.mjs"; import TestRegister from "../lib/TestRegister.mjs"; -/*import "./tests/nodeApi.mjs"; +import "./tests/nodeApi.mjs"; import "./tests/operations.mjs"; import "./tests/File.mjs"; import "./tests/Dish.mjs"; import "./tests/NodeDish.mjs"; import "./tests/Utils.mjs"; -import "./tests/Categories.mjs";*/ +import "./tests/Categories.mjs"; const testStatus = { allTestsPassing: true, diff --git a/tests/operations/index.mjs b/tests/operations/index.mjs index f6205cd9..49efbf8d 100644 --- a/tests/operations/index.mjs +++ b/tests/operations/index.mjs @@ -17,7 +17,7 @@ import { } from "../lib/utils.mjs"; import TestRegister from "../lib/TestRegister.mjs"; -/*import "./tests/BCD.mjs"; +import "./tests/BCD.mjs"; import "./tests/BSON.mjs"; import "./tests/BaconCipher.mjs"; import "./tests/Base58.mjs"; @@ -40,9 +40,9 @@ import "./tests/CSV.mjs"; import "./tests/DateTime.mjs"; import "./tests/ExtractEmailAddresses.mjs"; import "./tests/Fork.mjs"; -import "./tests/FromDecimal.mjs";*/ +import "./tests/FromDecimal.mjs"; import "./tests/Gsm7.mjs"; -/*import "./tests/Gzip.mjs"; +import "./tests/Gzip.mjs"; import "./tests/Gunzip.mjs"; import "./tests/Hash.mjs"; import "./tests/HaversineDistance.mjs"; @@ -107,7 +107,7 @@ import "./tests/CBOREncode.mjs"; import "./tests/CBORDecode.mjs"; import "./tests/JA3Fingerprint.mjs"; import "./tests/JA3SFingerprint.mjs"; -import "./tests/HASSH.mjs";*/ +import "./tests/HASSH.mjs"; // Cannot test operations that use the File type yet diff --git a/tests/operations/tests/Gsm7.mjs b/tests/operations/tests/Gsm7.mjs index ad2e6623..203877a8 100644 --- a/tests/operations/tests/Gsm7.mjs +++ b/tests/operations/tests/Gsm7.mjs @@ -39,32 +39,13 @@ TestRegister.addTests([ ], }, { - name: "To GSM-7: not padding a 7 chars SMS", - input: "7Chars.", - expectedOutput: "b7 21 3a 2c 9f bb 00", + name: "To GSM-7: smiley", + input: "😀", + expectedOutput: "character '😀' is not present in current charset+extension.
A real device would encode this SMS using UCS-2 (UTF-16)", recipeConfig: [ { op: "To GSM-7", args: ["Default", "Default", false], - }, - { - op: "To Hex", - args: ["Space", 0], - } - ], - }, - { - name: "To GSM-7: padding a 7 chars SMS", - input: "7Chars.", - expectedOutput: "b7 21 3a 2c 9f bb 1a", - recipeConfig: [ - { - op: "To GSM-7", - args: ["Default", "Default", true], - }, - { - op: "To Hex", - args: ["Space", 0], } ], }, @@ -97,5 +78,95 @@ TestRegister.addTests([ args: ["Default", "Default", true], } ], + }, + { + name: "GSM-7: padding/not unpadding a %7 chars SMS", + input: "7Chars.", + expectedOutput: "7Chars.\r", + recipeConfig: [ + { + op: "To GSM-7", + args: ["Default", "Default", true], + }, + { + op: "From GSM-7", + args: ["Default", "Default", false], + } + ], + }, + { + name: "GSM-7: padding/unpadding a %7 chars SMS", + input: "twenty three characters", + expectedOutput: "twenty three characters", + recipeConfig: [ + { + op: "To GSM-7", + args: ["Default", "Default", true], + }, + { + op: "From GSM-7", + args: ["Default", "Default", true], + } + ], + }, + { + name: "GSM-7: not padding/not unpadding a %7 chars SMS", + input: "<15 characters>", + expectedOutput: "<15 characters>@", + recipeConfig: [ + { + op: "To GSM-7", + args: ["Default", "Default", false], + }, + { + op: "From GSM-7", + args: ["Default", "Default", false], + } + ], + }, + { + name: "GSM-7: padding/not unpadding a 8 chars SMS", + input: "8 chars.", + expectedOutput: "8 chars.", + recipeConfig: [ + { + op: "To GSM-7", + args: ["Default", "Default", true], + }, + { + op: "From GSM-7", + args: ["Default", "Default", false], + } + ], + }, + { + name: "GSM-7: padding/not unpadding a 8 chars SMS with final CR", + input: "8 chars\r", + expectedOutput: "8 chars\r\r", + recipeConfig: [ + { + op: "To GSM-7", + args: ["Default", "Default", true], + }, + { + op: "From GSM-7", + args: ["Default", "Default", false], + } + ], + }, + { + name: "GSM-7: padding/unpadding a 8 chars SMS with final CR", + input: "8 chars\r", + expectedOutput: "8 chars\r\r", + recipeConfig: [ + { + op: "To GSM-7", + args: ["Default", "Default", true], + }, + { + op: "From GSM-7", + args: ["Default", "Default", true], + } + ], } ]);