mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-28 19:27:44 +00:00
Merge pull request #12882 from keymanapp/fix/common/web/types/1288-handle-invalid-order-and-tertiary-arguments-to-ElementString-fromString
fix(common/web): handle invalid order and tertiary arguments to ElementString.fromString()
This commit is contained in:
commit
d5c3e43f20
2 changed files with 28 additions and 6 deletions
|
|
@ -104,8 +104,8 @@ export class ElementString extends Array<ElemElement> {
|
|||
typeFlag |= constants.elem_flags_type_str;
|
||||
}
|
||||
}
|
||||
elem.order = orders.length ? parseInt(orders[i], 10) : 0;
|
||||
elem.tertiary = tertiaries.length ? parseInt(tertiaries[i], 10) : 0;
|
||||
elem.order = orders.length ? this.parseIntOrZero(orders[i]) : 0;
|
||||
elem.tertiary = tertiaries.length ? this.parseIntOrZero(tertiaries[i]) : 0;
|
||||
elem.flags = ElemElementFlags.none |
|
||||
(ElemElementFlags.type & typeFlag) |
|
||||
(tertiary_bases?.[i] == '1' /* TODO-LDML: or 'true'? */ ? ElemElementFlags.tertiary_base : 0) |
|
||||
|
|
@ -125,5 +125,9 @@ export class ElementString extends Array<ElemElement> {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
private static parseIntOrZero(str: string): number {
|
||||
const num = parseInt(str, 10);
|
||||
return !Number.isNaN(num) ? num : 0;
|
||||
}
|
||||
}
|
||||
;
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ describe('Test of ElementString file', () => {
|
|||
];
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
it.skip('can handle order string that is too short', () => {
|
||||
it('can handle order string that is too short', () => {
|
||||
sections.strs.allocString = stubStrsAllocString_Char;
|
||||
const actual = ElementString.fromStrings(
|
||||
sections,
|
||||
|
|
@ -156,7 +156,7 @@ describe('Test of ElementString file', () => {
|
|||
];
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
it.skip('can handle non-number in order string', () => {
|
||||
it('can handle non-number in order string', () => {
|
||||
sections.strs.allocString = stubStrsAllocString_Char;
|
||||
const actual = ElementString.fromStrings(
|
||||
sections,
|
||||
|
|
@ -200,7 +200,7 @@ describe('Test of ElementString file', () => {
|
|||
];
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
it.skip('can handle tertiary string that is too short', () => {
|
||||
it('can handle tertiary string that is too short', () => {
|
||||
sections.strs.allocString = stubStrsAllocString_Char;
|
||||
const actual = ElementString.fromStrings(
|
||||
sections,
|
||||
|
|
@ -215,7 +215,7 @@ describe('Test of ElementString file', () => {
|
|||
];
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
it.skip('can handle non-number in tertiary string', () => {
|
||||
it('can handle non-number in tertiary string', () => {
|
||||
sections.strs.allocString = stubStrsAllocString_Char;
|
||||
const actual = ElementString.fromStrings(
|
||||
sections,
|
||||
|
|
@ -428,6 +428,24 @@ describe('Test of ElementString file', () => {
|
|||
assert.isFalse(one.isEqual(two));
|
||||
});
|
||||
});
|
||||
describe('Test of parseIntOrZero()', () => {
|
||||
it('returns a number for a valid string', () => {
|
||||
const num = ElementString['parseIntOrZero']('1');
|
||||
assert.equal(num, 1);
|
||||
});
|
||||
it('returns zero for an invalid string', () => {
|
||||
const num = ElementString['parseIntOrZero']('A');
|
||||
assert.equal(num, 0);
|
||||
});
|
||||
it('returns zero for undefined', () => {
|
||||
const num = ElementString['parseIntOrZero'](undefined);
|
||||
assert.equal(num, 0);
|
||||
});
|
||||
it('returns zero for a null string', () => {
|
||||
const num = ElementString['parseIntOrZero'](null);
|
||||
assert.equal(num, 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue