diff --git a/packages/primeng/src/inputmask/inputmask.ts b/packages/primeng/src/inputmask/inputmask.ts index 94fff6ea702..d74ff39060c 100755 --- a/packages/primeng/src/inputmask/inputmask.ts +++ b/packages/primeng/src/inputmask/inputmask.ts @@ -498,6 +498,18 @@ export class InputMaskDirective extends BaseComponent { return pos; } + /** + * Count the number of fixed (non-editable) mask characters in the range [from, to). + * Fixed characters are those where tests[k] is null (e.g. separators like '.' or '/'). + */ + private countFixedChars(from: number, to: number): number { + let count = 0; + for (let k = from; k < to; k++) { + if (!this.tests[k]) count++; + } + return count; + } + shiftL(begin: number, end: number) { let i, j; @@ -507,6 +519,12 @@ export class InputMaskDirective extends BaseComponent { for (i = begin, j = this.seekNext(end); i < (this.len as number); i++) { if (this.tests[i]) { + // Stop shifting if j has crossed more fixed-mask separators than i has. + // This prevents digits from bleeding across section boundaries (e.g. 99.99.9999). + if (this.countFixedChars(begin, i + 1) !== this.countFixedChars(end + 1, j + 1)) { + break; + } + if (j < (this.len as number) && this.tests[i].test(this.buffer[j])) { this.buffer[i] = this.buffer[j]; this.buffer[j] = this.getPlaceholder(j); @@ -1070,6 +1088,18 @@ export class InputMask extends BaseInput { return pos; } + /** + * Count the number of fixed (non-editable) mask characters in the range [from, to). + * Fixed characters are those where tests[k] is null (e.g. separators like '.' or '/'). + */ + private countFixedChars(from: number, to: number): number { + let count = 0; + for (let k = from; k < to; k++) { + if (!this.tests[k]) count++; + } + return count; + } + shiftL(begin: number, end: number) { let i, j; @@ -1079,6 +1109,12 @@ export class InputMask extends BaseInput { for (i = begin, j = this.seekNext(end); i < (this.len as number); i++) { if (this.tests[i]) { + // Stop shifting if j has crossed more fixed-mask separators than i has. + // This prevents digits from bleeding across section boundaries (e.g. 99.99.9999). + if (this.countFixedChars(begin, i + 1) !== this.countFixedChars(end + 1, j + 1)) { + break; + } + if (j < (this.len as number) && this.tests[i].test(this.buffer[j])) { this.buffer[i] = this.buffer[j]; this.buffer[j] = this.getPlaceholder(j);