WordPress.org

Make WordPress Core

Opened 12 months ago

Last modified 12 months ago

#51721 new defect (bug)

wp-admin/js/post.(min.)js does not successfully validate post dates within years 0000—0100

Reported by: wongjn Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 2.9
Component: Editor Keywords:
Focuses: javascript Cc:

Description

When adding or editing a post, wp-admin/js/post.(min.)js does not correctly set the year on a JavaScript Date object when validating the post date.

To reproduce:

  1. Add or edit a post
  2. In the Publish meta box, click Edit next to the publish date.
  3. Enter a validate date, with the year in the range 0—100.
  4. See that the date input is highlighted red and marked invalid.

In depth

This happens because in JavaScript, when passing a two-digit year to the Date constructor, it thinks that it is for the 1900 century. Even passing a string such as 0050 seems to be type-casted to a number. See more on MDN.

Attachments (3)

1900–1999_post_date_validation.patch (536 bytes) - added by wongjn 12 months ago.
Initial patch proposal
Posts ‹ New Test Site — WordPress 2020-11-10 10-09-38.jpg (113.0 KB) - added by adamsilverstein 12 months ago.
Edit Post ‹ New Test Site — WordPress 2020-11-10 10-10-24.jpg (74.2 KB) - added by adamsilverstein 12 months ago.

Download all attachments as: .zip

Change History (9)

@wongjn
12 months ago

Initial patch proposal

#1 @TimothyBlynJacobs
12 months ago

  • Component changed from General to Editor
  • Focuses ui removed

#2 @helen
12 months ago

  • Version changed from trunk to 2.9

This seems reasonable, just changing the version for triage purposes. I'm guessing this has existed since... forever. Traced code back to 2.9 and it keeps going from there (see #10309).

#3 @adamsilverstein
12 months ago

Hi @wongjn thanks for the bug report.

I tried to reproduce this without any success. Are you using the current version of WordPress with the block editor or perhaps on an older version or using the Classic Editor plugin?

Using the block editor I had no trouble setting the data to the year 50 or 0050. I also tested updating the date using the quick edit feature on the post list screen and had no trouble entering a year below 100.

Can you add any additional details about how to reproduce this error or can you attach a screenshot showing the error in context?

Last edited 12 months ago by adamsilverstein (previous) (diff)

#4 @wongjn
12 months ago

Hi @adamsilverstein,

Sorry, I did fail to mention in the original post that this is with the "old" post UI, indeed such as when using the Classic Editor plugin. It seems the JavaScript validation that is in error is only used there and not the other locations you have tested (block editor, quick edit).

#5 @adamsilverstein
12 months ago

Thanks for clarifying.

I'm wondering if this code is used in core at all and could be moved to the Classic Editor plugin? Do we even enqueue post.js in core any more? If not, can we move this file and its maintenance effort to the classic editor plugin?

cc: @azaozz

#6 @wongjn
12 months ago

Custom post types could still use this UI with post.js.

Note: See TracTickets for help on using tickets.