1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

[JS] Fix few errors around AFSpecial_Keystroke

- @cincodenada found some errors which are fixed in this patch;
 - it partially fixes issue #14306;
 - add some tests.
This commit is contained in:
Calixte Denizet 2022-01-08 00:11:40 +01:00
parent 290cbc5232
commit 6369617e6f
3 changed files with 185 additions and 16 deletions

View file

@ -433,11 +433,8 @@ class AForm {
}
psf = this.AFMakeNumber(psf);
if (psf === null) {
throw new Error("Invalid psf in AFSpecial_Format");
}
let formatStr = "";
let formatStr;
switch (psf) {
case 0:
formatStr = "99999";
@ -486,7 +483,7 @@ class AForm {
]);
function _checkValidity(_value, _cMask) {
for (let i = 0, ii = value.length; i < ii; i++) {
for (let i = 0, ii = _value.length; i < ii; i++) {
const mask = _cMask.charAt(i);
const char = _value.charAt(i);
const checker = checkers.get(mask);
@ -546,9 +543,6 @@ class AForm {
}
psf = this.AFMakeNumber(psf);
if (psf === null) {
throw new Error("Invalid psf in AFSpecial_Keystroke");
}
let formatStr;
switch (psf) {
@ -559,12 +553,8 @@ class AForm {
formatStr = "99999-9999";
break;
case 2:
const finalLen =
event.value.length +
event.change.length +
event.selStart -
event.selEnd;
if (finalLen >= 8) {
const value = this.AFMergeChange(event);
if (value.length > 8 || value.startsWith("(")) {
formatStr = "(999) 999-9999";
} else {
formatStr = "999-9999";

View file

@ -26,8 +26,8 @@ class Event {
this.richChange = data.richChange || [];
this.richChangeEx = data.richChangeEx || [];
this.richValue = data.richValue || [];
this.selEnd = data.selEnd || -1;
this.selStart = data.selStart || -1;
this.selEnd = data.selEnd ?? -1;
this.selStart = data.selStart ?? -1;
this.shift = data.shift || false;
this.source = data.source || null;
this.target = data.target || null;