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

[RTM] Improve zlib stream check #41

Merged
merged 1 commit into from
Nov 28, 2017
Merged

[RTM] Improve zlib stream check #41

merged 1 commit into from
Nov 28, 2017

Conversation

ausi
Copy link
Member

@ausi ausi commented Oct 31, 2017

Fixes #38

@ausi ausi added the bug label Oct 31, 2017
@ausi ausi self-assigned this Oct 31, 2017
@ausi ausi requested a review from discordier October 31, 2017 14:55
@ausi ausi mentioned this pull request Oct 31, 2017
@ausi ausi changed the title Improve zlib stream check [RTM] Improve zlib stream check Oct 31, 2017
&& ($reader = new XMLReader)
&& @$reader->open('compress.zlib://data:text/xml,<x/>') === true
&& @$reader->read() === true
&& @$reader->close() === true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think it is wrong to test the object instantiation.

if (null === $zlibSupport) {
    $zlibSupport = false;

    if (\in_array('compress.zlib', stream_get_wrappers(), true)) {
        $reader = new XMLReader();

        if (true ===  @$reader->open('compress.zlib://data:text/xml,<x/>')) {
            $zlibSupport = true;
        }

        @$reader->close();
    }
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code doesn’t test the read() method. How about this?

if (null === $zlibSupport) {
    $reader = new XMLReader();
    $zlibSupport =
        \in_array('compress.zlib', stream_get_wrappers(), true)
        && true === @$reader->open('compress.zlib://data:text/xml,<x/>')
        && true === @$reader->read()
    ;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test file is 'compress.zlib://data:text/xml,<x/>'. How can this be opened but not read?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example compress.zlib://data:text/xml, can be opened but not read.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but that is not our test string, is it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but if the compress.zlib wrapper doesn’t work correctly it could currupt the <x/> and this would result in read() returning false.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very unlikely but then just keep it as it is.

@ausi ausi merged commit cbfd2d5 into contao:master Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants