Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method getDateModified of RSS reader doesn't iterate over different formats #32

Closed
Klaasie opened this issue Dec 16, 2020 · 2 comments · Fixed by #33
Closed

Method getDateModified of RSS reader doesn't iterate over different formats #32

Klaasie opened this issue Dec 16, 2020 · 2 comments · Fixed by #33
Assignees
Labels
Bug Something isn't working
Milestone

Comments

@Klaasie
Copy link

Klaasie commented Dec 16, 2020

Bug Report

Q A
Version(s) 2.13.0

Summary

The current code suggest that when retrieving the date modified variable it will attempt to create it from 3 different formats: RSS, RFC822 and RFC2822. This doesn't happen because the method used date_create_from_format doesn't throw an exception.
This also means that if the format is not recognised at all the exception won't be thrown.

Current behavior

If the given date doesn't match the first format tested (RSS) the variable will resolve into false and the loop will break there.

How to reproduce

Read an RSS feed with a date modified format different from RSS (D, d M Y H:i:s O).

Expected behavior

The code will iterate over all 3 different formats and if unable to create the datetime object it will throw an exception saying the date format was not recognised.

For reference, the piece of code with the bug:
https://github.com/laminas/laminas-feed/blob/2.13.x/src/Reader/Feed/Rss.php#L205

$dateStandards = [
    DateTime::RSS,
    DateTime::RFC822,
    DateTime::RFC2822,
    null,
];

foreach ($dateStandards as $standard) {
    try {
        $date = date_create_from_format($standard, $dateModified);
        break;
    } catch (\Exception $e) {
        if ($standard === null) {
            throw new Exception\RuntimeException(
                'Could not load date due to unrecognised format'
                . ' (should follow RFC 822 or 2822): ' . $e->getMessage(),
                0,
                $e
            );
        }
    }
}
@Klaasie Klaasie added the Bug Something isn't working label Dec 16, 2020
@froschdesign
Copy link
Member

@Klaasie
Thanks for the issue report, I will check the problem.

@froschdesign froschdesign self-assigned this Dec 16, 2020
@froschdesign froschdesign changed the title get date modified doesn't iterate over different formats Method getDateModified of RSS reader doesn't iterate over different formats Dec 20, 2020
@froschdesign froschdesign added this to the 2.13.1 milestone Dec 21, 2020
froschdesign added a commit to froschdesign/laminas-feed that referenced this issue Dec 22, 2020
@weierophinney
Copy link
Member

Fixed with #33.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
3 participants