mirror of
https://github.com/keymanapp/keyman.git
synced 2026-10-12 08:57:30 +00:00
feat(developer): use util.isValidUnicode() to check codePoints; remove ci_publish_npm
This commit is contained in:
parent
d8bb132f64
commit
50cdfbeb09
3 changed files with 12 additions and 6 deletions
|
|
@ -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 '"';
|
||||
|
|
|
|||
|
|
@ -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],
|
||||
|
|
|
|||
|
|
@ -47,4 +47,3 @@ do_test() {
|
|||
}
|
||||
|
||||
builder_run_action test do_test
|
||||
#builder_run_action publish ci_publish_npm
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue