Problem/Motivation

The pre-installed view "Archive" will crash to a white screen with the text "The website encountered an unexpected error. Please try again later." if an invalid date is entered in the URL as the context filter.

The "Created Year + Month" context filter wants the format to be YYYYMM. Anything that strays from this format results in white screen of death.

My expected behavior for an invalid date would either a "No results" page, "summary page" or a "Page not found" error. The white screen is a terrible user experience and strikes me as being a bug.

Steps to reproduce

1. Clean install of Drupal 8.8.1
2. Enable "Archive" view
3. Enter any of the following paths "/archive/202013" or "/archive/20191201" or "/archive/foo"

Proposed resolution

BEFORE

before

AFTER

after

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

Robert Gomez created an issue. See original summary.

robert gomez’s picture

Issue summary: View changes
avpaderno’s picture

Version: 8.8.1 » 8.8.x-dev

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
larowlan’s picture

Issue tags: +Novice, +Bug Smash Initiative

The view should have argument validation added

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

anjali rathod’s picture

Assigned: Unassigned » anjali rathod

Unable to reproduce the error.

avpaderno’s picture

Title: Views: Pre-installed "Archive" view crashes to white screen if invalid date format in context filter » Pre-installed "Archive" view crashes to white screen if invalid date format in context filter
anjali rathod’s picture

Assigned: anjali rathod » Unassigned
jobsons’s picture

Assigned: Unassigned » jobsons

I'll work on it.

jobsons’s picture

Assigned: jobsons » Unassigned

Unassigning the task

diegors’s picture

Assigned: Unassigned » diegors

I'll look into that.

diegors’s picture

Assigned: diegors » Unassigned
Status: Active » Needs review
StatusFileSize
new2.23 KB

I found the bug and created the patch to fix it.

Now returns a 404 page.

diegors’s picture

Assigned: Unassigned » diegors
Status: Needs review » Needs work

I just realize that I made a mistake, I will keep working on the bug.

Munavijayalakshmi’s picture

Assigned: diegors » Munavijayalakshmi
StatusFileSize
new1.12 KB

Rectified the following errors,

217 | ERROR | [x] Trailing punctuation for @see references is not
| | allowed.
283 | ERROR | [x] Trailing punctuation for @see references is not
| | allowed.

Munavijayalakshmi’s picture

Version: 9.4.x-dev » 9.5.x-dev
Assigned: Munavijayalakshmi » Unassigned
Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 17: 3107284-16.patch, failed testing. View results

diegors’s picture

Assigned: Unassigned » diegors
diegors’s picture

Assigned: diegors » Unassigned
Status: Needs work » Needs review
StatusFileSize
new614 bytes

After tests, I realized that the error happens in file core/modules/views/src/Plugin/views/argument/YearMonthDate.php in title() function:

  public function title() {
    return $this->dateFormatter->format(strtotime($this->argument . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
  }

When the title receives a value that is not a valid date, this patch fixes it, but I am not sure if is the correct way.

The previous patch should be removed.

gquisini’s picture

Assigned: Unassigned » gquisini

I'll be reviewing.

gquisini’s picture

Assigned: gquisini » Unassigned
StatusFileSize
new603 bytes
new486 bytes

So, #21 patch worked, no more "white screen of death". I just changed the message to something more understandable.

lucassc’s picture

Assigned: Unassigned » lucassc
lucassc’s picture

StatusFileSize
new612 bytes
new655 bytes

Hi!

I applied patch in #23 for 9.5.x-dev and works fine, instead of the "white screen of death" I saw a much more elegant "No results" page.

I'm attaching a suggestion to improve code readability. Please, review this.

lucassc’s picture

Assigned: lucassc » Unassigned
gquisini’s picture

Assigned: Unassigned » gquisini

I'll be doing the review.

gquisini’s picture

Assigned: gquisini » Unassigned
Status: Needs review » Reviewed & tested by the community

Everything is working and now the code is easier to understand.

quietone’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
Issue tags: +Usability

Would be nice to have this fixed, thanks for getting this closer to commit.

This is changing the user insterface, adding usability tag. The display message needs to be reviewed and the text agreed to.

A before and after screenshot would be helpful, both in the Issue summary, not a comment. The before one should be /archive, not the error message.

There are several steps, or gates, that an issue must pass before it is marked RTBC. For most issues following step 10 in the Review a patch or merge request task of the Contributor guide is sufficient. The complete list of core gates has more topics.

vitorbs’s picture

Assigned: Unassigned » vitorbs

I'll work on this one.

vitorbs’s picture

StatusFileSize
new17.5 KB

I applied the patch #25 and works fine, the whit screen error is not appearing anymore as you can see on the screenshots above.

And i also changed the error message to "No records found", what do you think?

vitorbs’s picture

StatusFileSize
new55.75 KB
vitorbs’s picture

StatusFileSize
new618 bytes
vitorbs’s picture

StatusFileSize
new458 bytes
vitorbs’s picture

Assigned: vitorbs » Unassigned
Status: Needs work » Needs review
vitorbs’s picture

Issue summary: View changes

I added the after and before screenshots in the issue summary.

sophiavs’s picture

Assigned: Unassigned » sophiavs

I'll do the review

sophiavs’s picture

Assigned: sophiavs » Unassigned

I tested the last patch and it stopped the error message to show when trying to access a archive view that doesn't exist. Testing with other view it didn't cause any bug.

I think the message "No records found" is good and simple to understand.

nikhilraut’s picture

Assigned: Unassigned » nikhilraut
nikhilraut’s picture

Assigned: nikhilraut » Unassigned
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new44.82 KB
new256.04 KB

After applying the patch #31 now showing message "No records found"

lendude’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Novice +Needs tests

Shouldn't this error message be translatable? But, as also pointed out in #21, I'm not sure this is the right solution. Shouldn't we fix the root cause of this and fix the offending title() method?

Also, this needs a test.

lucassc’s picture

Maybe we can validate the date format before using strtotime inside the title() method?

We could use a regex like /^[0-9]{4}(0[1-9]|1[0-2])$/, it would returns true for '202209' and false for '20191201', '202013' or 'foo'.

avpaderno’s picture

I am wondering: Does that happens only with the Archive view, or does it happen with all the views using that argument handler (which should not accepts values like foobar)?
In the first case, we should check what causes this issue with the Archive view. In the latter case, it's clearly the argument handler that needs to be fixed.

In both the cases, validating the value in title() would be too late, and it won't fix other issues.

avpaderno’s picture

I take that the argument handler for the Archive view is the YearMonthDate class, which uses the following code in YearMonthDate::title().

  return $this->dateFormatter->format(strtotime($this->argument . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');

Effectively, that code expects $this->argument to contain the correct value, but it's not its task to check the received argument is valid, since argument handlers have a validateArgument().

This is the code used by ArgumentPluginBase::validateArgument().

  // By using % in URLs, arguments could be validated twice; this eases
  // that pain.
  if (isset($this->argument_validated)) {
    return $this->argument_validated;
  }
  if ($this->isException($arg)) {
    return $this->argument_validated = TRUE;
  }
  $plugin = $this->getPlugin('argument_validator');
  return $this->argument_validated = $plugin->validateArgument($arg);
}

None of the argument plugins extends that method.

Either the argument_validator plugin set for the date_year_month argument handler is wrong or it is too permissive on the allowed values.

avpaderno’s picture

The issue summary needs to be updated, since it doesn't show the effective error that is causing the WSOD.

I thought it would be strtotime() that throws an exception or a warning when it receives a wrong argument, but that doesn't happen with echo strtotime("foobar15 00:00:00 UTC");.
The output is only different for PHP 4.3.0-4.3.11, 4.4.0-4.4.9, and 5.0.0-5.0.5, which show -1 instead of an empty string.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.