feat(developer): use util.isValidUnicode() to check codePoints; remove ci_publish_npm

This commit is contained in:
Sabine 2026-07-09 08:47:53 +02:00
parent d8bb132f64
commit 50cdfbeb09
3 changed files with 12 additions and 6 deletions

View file

@ -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 '&gt', '&lt',..
else if (m_nam) {
switch (m_nam[1].toLowerCase()) {
switch (m_nam[1]) {
case 'gt': return '>';
case 'lt': return '<';
case 'quot': return '"';

View file

@ -5,6 +5,7 @@ import { convertUtil } from '@keymanapp/common-types';
describe('convert-utils', function () {
describe('convertToUnicodeCharacter', function () {
[
["a&gt;b", 'a&gt;b'],
["<", '<'],
["a", 'a'],
["ሴ", 'ሴ'],
@ -26,6 +27,7 @@ describe('convert-utils', function () {
["&#4660;", 'ሴ'],
["&#7835;", "ẛ"],
["&#128518;", '😆'],
["&#x1F606;", '😆'],
["&#0003;", '\u0003'],
["&#1000000;", '󴉀'],
["&commat;", undefined],
@ -53,8 +55,8 @@ describe('convert-utils', function () {
["&#x;", undefined],
['&##', undefined],
['&##;', undefined],
["&#x10FFFF;", "􏿿"],
["&#1114111;", "􏿿"],
["&#x10FFFF;", undefined],
["&#1114111;", undefined],
["&#x110000;", undefined],
["&#x1000000;", undefined],
['&#1234;56', undefined],

View file

@ -47,4 +47,3 @@ do_test() {
}
builder_run_action test do_test
#builder_run_action publish ci_publish_npm