Revolution: Not open xml files

Created on 25 Sep 2019  ·  16Comments  ·  Source: modxcms/revolution

Bug report

Summary

Not open xml files. It problem in php class finfo. $finfo->file($file) return "application/xml". I'm solved edit file core/model/modx/modfilehandler.class.php.
`
public function isBinary($file) {
if (!file_exists($file) || !is_file($file)) {
return false;
}

    if (filesize($file) > 0 && class_exists('\finfo')) {
        $finfo = new \finfo(FILEINFO_MIME);
        $info_file = $finfo->file($file);
        //$this->modx->log(1,"$file ".$info_file);
        if(strpos($info_file, "application/xml") !== false) {
            //$this->modx->log(1,"$file ".$info_file);
            return false;
        }
        return substr($info_file, 0, 4) !== 'text';
    }

    $fh = @fopen($file, 'r');
    $blk = @fread($fh, 512);
    @fclose($fh);
    @clearstatcache();
    return (substr_count($blk, "^ -~" /*. "^\r\n"*/) / 512 > 0.3) || (substr_count($blk, "\x00") > 0);
}

`

bug

Most helpful comment

English translation:

I meet this problem on many sites. It is not clear what it depends on :-(. Maybe from the hosting, maybe from the php version.
I have this problem on Openserver v 5.2.2 https://ospanel.io/. Both on PHP-7.1 and on PHP-5.6. https://yadi.sk/i/hBV03Ci_s_0BPA

In the screenshot https://yadi.sk/i/Blnodo5kleHefg there is no "Edit" menu. And, accordingly, the file does not open for editing.

After editing the isBinary function, the https://yadi.sk/i/nfTjgFBiqTCjYg menu appears and the file opens https://yadi.sk/i/lNGEUtJR72KrKg

On hosting https://modhost.pro/ does not open, but on https://beget.com/en

All 16 comments

Thanks for taking time to report this issue. Can you provide the steps to reproduce this issue?

If English isn't your first language feel free to provide them in your native language.

Я встречаю эту проблему на многих сайтах. Не понятно от чего она зависит :-(. Может от хостинга, может от версии php. Эта проблема есть у меня на Openserver v 5.2.2 https://ospanel.io/ . И на PHP-7.1 и на PHP-5.6. https://yadi.sk/i/hBV03Ci_s_0BPA
На скриншоте https://yadi.sk/i/Blnodo5kleHefg нет меню "Редактировать". И, соответственно, файл не открывается на редактирование.
После правки функции isBinary https://yadi.sk/i/nfTjgFBiqTCjYg меню появляется и файл открывается https://yadi.sk/i/lNGEUtJR72KrKg

На хостинге https://modhost.pro/ не открывает, а на https://beget.com/ru открывает

English translation:

I meet this problem on many sites. It is not clear what it depends on :-(. Maybe from the hosting, maybe from the php version.
I have this problem on Openserver v 5.2.2 https://ospanel.io/. Both on PHP-7.1 and on PHP-5.6. https://yadi.sk/i/hBV03Ci_s_0BPA

In the screenshot https://yadi.sk/i/Blnodo5kleHefg there is no "Edit" menu. And, accordingly, the file does not open for editing.

After editing the isBinary function, the https://yadi.sk/i/nfTjgFBiqTCjYg menu appears and the file opens https://yadi.sk/i/lNGEUtJR72KrKg

On hosting https://modhost.pro/ does not open, but on https://beget.com/en

Thanks for taking time to report this issue and @Ibochkarev for translating.

Is it possible to share the original file that's causing this issue?

File on github is no different from the original file

@JoshuaLuckers asks you to share the xml file to reproduce the problem.

All xml files do not come off. For example core /model/schema/modx.mysql.schema.xml https://github.com/modxcms/revolution/blob/2.x/core/model/schema/modx.mysql.schema.xml :-)

Just that I checked the opening of core/model/schema/modx.mysql.schema.xml on 3 hosting sites:
https://modhost.pro/ - opens, without problems
https://reg.ru/ - opens, without problems
https://beget.com/ - opens, no problem

I can’t reproduce the error.

Reproduced the problem on the test site modhost.pro. On php 7.2 it opens, but on php 7.1 it no longer opens.
http://s19940.h10.modhost.pro/manager
Login: s19940
Pass: nYDb8QP59WKT

MODX Revolution 2.7.1-pl
Test site is open until 09/30/2019 14:23 Moscow time

I was able to reproduce this error; finfo returns the mime type application/xml; charset=us-ascii for the XML files that are not editable.

MDN has some info about the mime types for XML files:

application/xml if not readable from casual users (RFC 3023, section 3)
text/xml if readable from casual users (RFC 3023, section 3)
Source: Incomplete list of MIME types

And what to do with it?

We have to figure out why the mime type of the file is reported as application/xml instead of txt/xml.

I tried to find more information and what I found. Seems that it really a bug in PHP. https://bugs.php.net/bug.php?id=75380

Also the similar request in WP https://core.trac.wordpress.org/ticket/45670

I tested it on PHP 7.0, 7.1, and 7.2. It reproducible on the first two but seems to be fixed in PHP 7.2. I don't want to create some kind of workaround just to fix something, that is broken outside of MODX. Also, it broken only on too old PHP versions, even PHP 7.2 is not supported more. So, I am going to close it and one recommendation will be - to update the environment to a more fresh version.

Please, reopen, if you don't agree.

Was this page helpful?
0 / 5 - 0 ratings