diff --git a/projects/core/src/lib/classes/mask-model/mask-model.ts b/projects/core/src/lib/classes/mask-model/mask-model.ts index 9ee6fae84..805b50151 100644 --- a/projects/core/src/lib/classes/mask-model/mask-model.ts +++ b/projects/core/src/lib/classes/mask-model/mask-model.ts @@ -56,8 +56,7 @@ export class MaskModel implements ElementState { initialElementState, ); const isInvalidCharsInsertion = - // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with - value.slice(0, unmaskedFrom) === + value.slice(0, from) === calibrateValueByMask( { value: newUnmaskedLeadingValuePart, diff --git a/projects/core/src/lib/classes/mask-model/tests/mask-model-fixed-characters.spec.ts b/projects/core/src/lib/classes/mask-model/tests/mask-model-fixed-characters.spec.ts index 58f10e661..e951a3beb 100644 --- a/projects/core/src/lib/classes/mask-model/tests/mask-model-fixed-characters.spec.ts +++ b/projects/core/src/lib/classes/mask-model/tests/mask-model-fixed-characters.spec.ts @@ -110,4 +110,44 @@ describe('MaskModel | Fixed characters', () => { }); }); }); + + describe('Attempt to insert invalid characters for `overwriteMode: replace`', () => { + describe('mask expression contains leading characters – ["$", /d/, /d/]', () => { + const options: Required = { + ...MASKITO_DEFAULT_OPTIONS, + mask: ['$', /\d/, /\d/], + overwriteMode: 'replace', + }; + + it('$1|2 => Type A => $1|2', () => { + const value = '$12'; + const selection = [2, 2] as const; + const maskModel = new MaskModel({value, selection}, options); + + expect(() => maskModel.addCharacters(selection, 'q')).toThrow(); + expect(maskModel.value).toBe(value); + expect(maskModel.selection).toEqual(selection); + }); + + it('$|12 => Type $ => $|12', () => { + const value = '$12'; + const selection = [1, 1] as const; + const maskModel = new MaskModel({value, selection}, options); + + expect(() => maskModel.addCharacters(selection, '$')).toThrow(); + expect(maskModel.value).toBe(value); + expect(maskModel.selection).toEqual(selection); + }); + + it('$|12 => Type X => $|12', () => { + const value = '$12'; + const selection = [1, 1] as const; + const maskModel = new MaskModel({value, selection}, options); + + expect(() => maskModel.addCharacters(selection, 'X')).toThrow(); + expect(maskModel.value).toBe(value); + expect(maskModel.selection).toEqual(selection); + }); + }); + }); });