From 07010ce044e05866c2db1b6f4fd88f7e1f38b55b Mon Sep 17 00:00:00 2001 From: fambonomi Date: Mon, 12 Jan 2015 14:58:51 -0300 Subject: [PATCH 1/4] Fix issue with lowercase i18n am selector format Lowercase am selector formats are interpreted as PM because of an error in the am selector recognition logic, line 1238, jquery-ui-timepicker-addon.js: Original: ampm = $.inArray(treg[order.t].toUpperCase(), o.amNames) !== -1 ? 'AM' : 'PM'; Proposed: ampm = $.inArray(treg[order.t].toUpperCase(), o.amNames.toUpperCase()) !== -1 ? 'AM' : 'PM'; This bug causes lowercase am selector strings in amNames to be interpreted as PM when parsing the original value, resulting in inadvertent change of, for instance, 10 a.m. to 10 p.m. If the user didn't intend to change the date/time in the first place this is specially damaging because the user can miss the change and commit the form with the wrong time. Also note that amNames[0], which is used when wring back to the field is usually in lowercase. Fix: Using the same transformation (toUpperCase) in both sides preserves the equality. --- src/jquery-ui-timepicker-addon.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jquery-ui-timepicker-addon.js b/src/jquery-ui-timepicker-addon.js index 58d6653..fc0fe66 100644 --- a/src/jquery-ui-timepicker-addon.js +++ b/src/jquery-ui-timepicker-addon.js @@ -1235,7 +1235,7 @@ ampm = ''; resTime.ampm = ''; } else { - ampm = $.inArray(treg[order.t].toUpperCase(), o.amNames) !== -1 ? 'AM' : 'PM'; + ampm = $.inArray(treg[order.t].toUpperCase(), o.amNames.toUpperCase()) !== -1 ? 'AM' : 'PM'; resTime.ampm = o[ampm === 'AM' ? 'amNames' : 'pmNames'][0]; } } From d4f0764f91f31a1ab13a10b8d8fa251bac3e9d25 Mon Sep 17 00:00:00 2001 From: fambonomi Date: Mon, 12 Jan 2015 15:26:01 -0300 Subject: [PATCH 2/4] Other place with issue in am-pm detection There was an additional place where am-pm detection logic had de same problem. --- src/jquery-ui-timepicker-addon.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jquery-ui-timepicker-addon.js b/src/jquery-ui-timepicker-addon.js index fc0fe66..43b726b 100644 --- a/src/jquery-ui-timepicker-addon.js +++ b/src/jquery-ui-timepicker-addon.js @@ -810,7 +810,7 @@ second !== parseInt(this.second,10) || millisec !== parseInt(this.millisec,10) || microsec !== parseInt(this.microsec,10) || - (this.ampm.length > 0 && (hour < 12) !== ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1)) || + (this.ampm.length > 0 && (hour < 12) !== ($.inArray(this.ampm.toUpperCase(), this.amNames.toUpperCase()) !== -1)) || (this.timezone !== null && timezone !== this.timezone.toString()) // could be numeric or "EST" format, so use toString() ); From c9c3d5a09939b58353978197620f4cf2129f3294 Mon Sep 17 00:00:00 2001 From: fambonomi Date: Mon, 12 Jan 2015 15:33:09 -0300 Subject: [PATCH 3/4] My mistake on last commit This ocurence was not in error. Over-eager search-n-repl. --- src/jquery-ui-timepicker-addon.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jquery-ui-timepicker-addon.js b/src/jquery-ui-timepicker-addon.js index 43b726b..fc0fe66 100644 --- a/src/jquery-ui-timepicker-addon.js +++ b/src/jquery-ui-timepicker-addon.js @@ -810,7 +810,7 @@ second !== parseInt(this.second,10) || millisec !== parseInt(this.millisec,10) || microsec !== parseInt(this.microsec,10) || - (this.ampm.length > 0 && (hour < 12) !== ($.inArray(this.ampm.toUpperCase(), this.amNames.toUpperCase()) !== -1)) || + (this.ampm.length > 0 && (hour < 12) !== ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1)) || (this.timezone !== null && timezone !== this.timezone.toString()) // could be numeric or "EST" format, so use toString() ); From 1fb1dfe240ea1af2616cce96a4df630de2dbcd45 Mon Sep 17 00:00:00 2001 From: fambonomi Date: Mon, 19 Jan 2015 20:46:29 +0200 Subject: [PATCH 4/4] Corrected mistake, forgot to $.map toUpperCase Basically I was calling toUpperCase on an array instead of mapping and applying to each element. --- src/jquery-ui-timepicker-addon.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jquery-ui-timepicker-addon.js b/src/jquery-ui-timepicker-addon.js index fc0fe66..2a28a15 100644 --- a/src/jquery-ui-timepicker-addon.js +++ b/src/jquery-ui-timepicker-addon.js @@ -1235,7 +1235,7 @@ ampm = ''; resTime.ampm = ''; } else { - ampm = $.inArray(treg[order.t].toUpperCase(), o.amNames.toUpperCase()) !== -1 ? 'AM' : 'PM'; + ampm = $.inArray(treg[order.t].toUpperCase(), $.map(o.amNames, function (x,i) {return x.toUpperCase() })) !== -1 ? 'AM' : 'PM'; resTime.ampm = o[ampm === 'AM' ? 'amNames' : 'pmNames'][0]; } }