Skip to content

Conversation

@fambonomi
Copy link

Lowercase amNames selectors ignored and interpreted as PM because of an error in the am selector recognition logic, line 1238, jquery-ui-timepicker-addon.js
This error causes 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 (just oppened and closed the selector) this error can cause the form to be sent with the wrong time. Also note that amNames[0], which is used when wring back to the field is usually in lowercase for i18n files.
Fix: Using the same transformation (toUpperCase) in both sides preserves the equality.

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';

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.
There was an additional place where am-pm detection logic had de same problem.
This ocurence was not in error. Over-eager search-n-repl.
Basically I was calling toUpperCase on an array instead of mapping and applying to each element.
@trentrichardson
Copy link
Owner

Thanks for the fix. I merged it with the dev branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants