From 0f36c6807a28bf05cb6c29777ec2e28d98874fd3 Mon Sep 17 00:00:00 2001 From: Alassane Ndoye Date: Thu, 22 Aug 2024 14:33:49 +0000 Subject: [PATCH 1/3] fix(#9341): strip invisible characters --- api/src/services/report/smsparser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/services/report/smsparser.js b/api/src/services/report/smsparser.js index 43d4924a2d8..22bea0cfcae 100644 --- a/api/src/services/report/smsparser.js +++ b/api/src/services/report/smsparser.js @@ -32,7 +32,7 @@ const T_TABLE = { // TODO ensure everything in here is still needed const digitReplacer = c => T_TABLE[c]; const standardiseDigits = original => { - return original && original.toString().replace(/[०-९]/g, digitReplacer); + return original && stripInvisibleCharacters(original.toString().replace(/[०-९]/g, digitReplacer)); }; const isMuvukuFormat = (exports.isMuvukuFormat = msg => { From bcc2feeca2e12faaf54f6d7948a87aff7b8d6188 Mon Sep 17 00:00:00 2001 From: Alassane Ndoye Date: Fri, 23 Aug 2024 14:06:01 +0000 Subject: [PATCH 2/3] fix(#9364): add test for strip invisible characters --- .../mocha/services/report/smsparser.spec.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/api/tests/mocha/services/report/smsparser.spec.js b/api/tests/mocha/services/report/smsparser.spec.js index b1febafd9c6..100d23337c6 100644 --- a/api/tests/mocha/services/report/smsparser.spec.js +++ b/api/tests/mocha/services/report/smsparser.spec.js @@ -1670,4 +1670,27 @@ describe('sms parser', () => { chai.expect(config.translate.callCount).to.equal(2); }); + it('should correctly parse and standardize BS Year from Devanagari digits using parseField', () => { + const bsYearField = { type: 'bsYear' }; + const input = '२०८०'; // 2080 in Devanagari + const expected = '2080'; + const result = smsparser.parseField(bsYearField, input, 'year'); + chai.expect(result).to.equal(expected); + }); + + it('should correctly parse and standardize BS Month from Devanagari digits using parseField', () => { + const bsMonthField = { type: 'bsMonth' }; + const input = '०४'; // 04 in Devanagari + const expected = '04'; + const result = smsparser.parseField(bsMonthField, input, 'month'); + chai.expect(result).to.equal(expected); + }); + + it('should correctly parse and standardize BS Day from Devanagari digits using parseField', () => { + const bsDayField = { type: 'bsDay' }; + const input = '१५'; // 15 in Devanagari + const expected = '15'; + const result = smsparser.parseField(bsDayField, input, 'day'); + chai.expect(result).to.equal(expected); + }); }); From 72b70678cf26af7e481f8d65d3009a3d55751a7d Mon Sep 17 00:00:00 2001 From: Alassane Ndoye Date: Mon, 26 Aug 2024 10:30:10 +0000 Subject: [PATCH 3/3] fix(#9341): Test Case for Stripping Invisible Characters --- api/tests/mocha/services/report/smsparser.spec.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/tests/mocha/services/report/smsparser.spec.js b/api/tests/mocha/services/report/smsparser.spec.js index 100d23337c6..f2b9c31bbbb 100644 --- a/api/tests/mocha/services/report/smsparser.spec.js +++ b/api/tests/mocha/services/report/smsparser.spec.js @@ -1693,4 +1693,12 @@ describe('sms parser', () => { const result = smsparser.parseField(bsDayField, input, 'day'); chai.expect(result).to.equal(expected); }); + + it('should correctly parse and standardize BS Year from Devanagari digits and strip invisible characters', () => { + const bsYearField = { type: 'bsYear' }; + const input = '२\u200B०८०'; // 2080 in Devanagari with a zero-width space + const expected = '2080'; + const result = smsparser.parseField(bsYearField, input, 'year'); + chai.expect(result).to.equal(expected); + }); });