mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Improve date parsing in the js sandbox
If for example dd:mm is failing we just try with d:m which is equivalent to the regex /d{1,2}:m{1,2}/. This way it allows the user to forget the 0 for the first days/months.
This commit is contained in:
parent
e3caa3c6ee
commit
c14c3cfc9f
2 changed files with 21 additions and 2 deletions
|
@ -140,11 +140,26 @@ class AForm {
|
|||
return date;
|
||||
}
|
||||
|
||||
_parseDate(cFormat, cDate) {
|
||||
_parseDate(cFormat, cDate, strict = false) {
|
||||
let date = null;
|
||||
try {
|
||||
date = this._util.scand(cFormat, cDate);
|
||||
} catch {}
|
||||
if (!date) {
|
||||
if (strict) {
|
||||
return null;
|
||||
}
|
||||
let format = cFormat;
|
||||
if (/mm(?!m)/.test(format)) {
|
||||
format = format.replace("mm", "m");
|
||||
}
|
||||
if (/dd(?!d)/.test(format)) {
|
||||
format = format.replace("dd", "d");
|
||||
}
|
||||
try {
|
||||
date = this._util.scand(format, cDate);
|
||||
} catch {}
|
||||
}
|
||||
if (!date) {
|
||||
date = Date.parse(cDate);
|
||||
date = isNaN(date)
|
||||
|
@ -379,7 +394,7 @@ class AForm {
|
|||
return;
|
||||
}
|
||||
|
||||
if (this._parseDate(cFormat, value) === null) {
|
||||
if (this._parseDate(cFormat, value, /* strict = */ true) === null) {
|
||||
const invalid = GlobalConstants.IDS_INVALID_DATE;
|
||||
const invalid2 = GlobalConstants.IDS_INVALID_DATE2;
|
||||
const err = `${invalid} ${this._mkTargetName(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue