Skip to content

Commit

Permalink
Fix array passed to String.prototype.replace
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Mar 27, 2023
1 parent 8d39da5 commit 61e0586
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/DateTimeInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,13 @@ export default class DateTimeInput extends PureComponent {

let placeholder = formattedDate;
datePieces.forEach((datePiece, index) => {
const formattedDatePiece = formatDatePiece(datePiece, date);
const datePieceReplacement = datePieceReplacements[index];
placeholder = placeholder.replace(formattedDatePiece, datePieceReplacement);
const match = formatDatePiece(datePiece, date);

if (match) {
const formattedDatePiece = match[0];
const datePieceReplacement = datePieceReplacements[index];
placeholder = placeholder.replace(formattedDatePiece, datePieceReplacement);
}
});
// See: https://github.com/wojtekmaj/react-date-picker/issues/396
placeholder = placeholder.replace('17', 'y');
Expand Down

0 comments on commit 61e0586

Please sign in to comment.