From 50cdfbeb094b2f58f70c33790d7c8a71f29f2b0f Mon Sep 17 00:00:00 2001 From: Sabine Date: Thu, 9 Jul 2026 08:47:53 +0200 Subject: [PATCH] feat(developer): use util.isValidUnicode() to check codePoints; remove ci_publish_npm --- common/web/types/src/util/convert-utils.ts | 11 ++++++++--- common/web/types/tests/util/convert-utils.tests.ts | 6 ++++-- developer/src/kmc-convert/build.sh | 1 - 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/common/web/types/src/util/convert-utils.ts b/common/web/types/src/util/convert-utils.ts index 7b334836b3..c3c6656afb 100644 --- a/common/web/types/src/util/convert-utils.ts +++ b/common/web/types/src/util/convert-utils.ts @@ -8,6 +8,8 @@ * */ +import { util } from '@keymanapp/common-types'; + /** * @brief function to convert a character, numeric character reference or a unicode value to a character or unicode Codepoint * if input is a valid single character or Codepoint like 'c','Γ€', 'ሴ', 'ẘ', '😎', the same character or Codepoint is returned (e.g. 'c' -> 'c', '😎' -> '😎') @@ -46,24 +48,27 @@ export function convertToUnicodeCharacter(inputString: string): string | undefin // valid '&#x...' if (m_hex) { const codePoint_h = parseInt(m_hex[1], 16); + // Reject surrogates and invalid codepoints - if ((codePoint_h >= 0xD800 && codePoint_h <= 0xDFFF) || codePoint_h > 0x10FFFF) { + if (!(util.isValidUnicode(codePoint_h))) { return undefined; } return String.fromCodePoint(codePoint_h); } + // valid '&#...' else if (m_dec) { const codePoint_d = parseInt(m_dec[1], 10); + // Reject surrogates and invalid codepoints - if ((codePoint_d >= 0xD800 && codePoint_d <= 0xDFFF) || codePoint_d > 0x10FFFF) { + if (!(util.isValidUnicode(codePoint_d))) { return undefined; } return String.fromCodePoint(codePoint_d); } // valid '>', '<',.. else if (m_nam) { - switch (m_nam[1].toLowerCase()) { + switch (m_nam[1]) { case 'gt': return '>'; case 'lt': return '<'; case 'quot': return '"'; diff --git a/common/web/types/tests/util/convert-utils.tests.ts b/common/web/types/tests/util/convert-utils.tests.ts index 1bb438cc78..f6da09fdb4 100644 --- a/common/web/types/tests/util/convert-utils.tests.ts +++ b/common/web/types/tests/util/convert-utils.tests.ts @@ -5,6 +5,7 @@ import { convertUtil } from '@keymanapp/common-types'; describe('convert-utils', function () { describe('convertToUnicodeCharacter', function () { [ + ["a>b", 'a>b'], ["<", '<'], ["a", 'a'], ["ሴ", 'ሴ'], @@ -26,6 +27,7 @@ describe('convert-utils', function () { ["ሴ", 'ሴ'], ["ẛ", "αΊ›"], ["😆", 'πŸ˜†'], + ["😆", 'πŸ˜†'], ["", '\u0003'], ["󴉀", '󴉀'], ["@", undefined], @@ -53,8 +55,8 @@ describe('convert-utils', function () { ["&#x;", undefined], ['&##', undefined], ['&##;', undefined], - ["􏿿", "τΏΏ"], - ["􏿿", "τΏΏ"], + ["􏿿", undefined], + ["􏿿", undefined], ["�", undefined], ["�", undefined], ['Ӓ56', undefined], diff --git a/developer/src/kmc-convert/build.sh b/developer/src/kmc-convert/build.sh index 51be0e4dce..a11ca3396a 100755 --- a/developer/src/kmc-convert/build.sh +++ b/developer/src/kmc-convert/build.sh @@ -47,4 +47,3 @@ do_test() { } builder_run_action test do_test -#builder_run_action publish ci_publish_npm