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

Fix Language parsing when parse_ini_file disabled #15620

Merged
merged 14 commits into from May 3, 2017
Merged

Fix Language parsing when parse_ini_file disabled #15620

merged 14 commits into from May 3, 2017

Conversation

PhilETaylor
Copy link
Contributor

@PhilETaylor PhilETaylor commented Apr 27, 2017

closes #15587

Use sensible code to process ini files when moronic web hosts disable parse_ini_file in php.ini

Please test

closes #15587

Use sensible code available in FOF to process ini files when moronic web hosts disable parse_ini_file in php.ini

Please test
@dgrammatiko
Copy link
Contributor

@PhilETaylor shouldn't this be conditional, if php_ini_parse not exist then use FOF?

@PhilETaylor

This comment was marked as abuse.

@PhilETaylor

This comment was marked as abuse.

@dgrammatiko
Copy link
Contributor

dgrammatiko commented Apr 27, 2017

Still, this will be faster (one less file, less memory for the good hosts):

		if (!function_exists('parse_ini_file'))
		{
         		$strings = FOFUtilsIniParser::parse_ini_file($filename, true);
		}
		else
		{
			$strings = @parse_ini_file($filename);
		}

@zero-24
Copy link
Member

zero-24 commented Apr 27, 2017

Should we really create another dependencey to FOF where we try to remove it at other places?

@PhilETaylor

This comment was marked as abuse.

$strings = @parse_ini_file($filename);
if (!function_exists('parse_ini_file'))
{
return FOFUtilsIniParser::parse_ini_file_php($filename, true);
Copy link
Contributor

@csthomas csthomas Apr 27, 2017

Choose a reason for hiding this comment

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

Why we can not use the old way before #13407?

return @parse_ini_string(file_get_contents($filename));

This comment was marked as abuse.

Copy link
Member

@zero-24 zero-24 Apr 27, 2017

Choose a reason for hiding this comment

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

As long as we restore:

	$contents = file_get_contents($filename);
	$contents = str_replace('_QQ_', '"\""', $contents);
	$strings = @parse_ini_string($contents);

That should do the trick.

In case the new function is not there.

This comment was marked as abuse.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO the idea was improve performance. Please replace above line as I suggested.

Copy link
Member

@zero-24 zero-24 Apr 27, 2017

Choose a reason for hiding this comment

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

No just as fallback when the new code don't work for b/c? (as respose to @PhilETaylor)

Copy link
Contributor

Choose a reason for hiding this comment

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

This $contents = str_replace('_QQ_', '"\""', $contents); is not needed. I tested on php7.0

This comment was marked as abuse.

Copy link
Contributor

Choose a reason for hiding this comment

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

Obviously just using parse_ini_file is simpler than using parse_ini_string and file_get_contents. That's probably the main reason it has been changed.
And as you can read in that PR, there is some automatic handling of QQ

@Bakual
Copy link
Contributor

Bakual commented Apr 27, 2017

Using FOF certainly isn't right.

@PhilETaylor

This comment was marked as abuse.

@zero-24
Copy link
Member

zero-24 commented Apr 27, 2017

@PhilETaylor

remove QQ replacement (apparently its not needed)

why do you think so?

parse_ini_file can do that: http://php.net/manual/en/function.parse-ini-file.php

Constants may also be parsed in the ini file so if you define a constant as an ini value before running parse_ini_file(), it will be integrated into the results.

But i can not find something like that for parse_ini_string: http://php.net/manual/en/function.parse-ini-string.php

I have not tested this yet but maybe you have..

@PhilETaylor

This comment was marked as abuse.

@zero-24
Copy link
Member

zero-24 commented Apr 27, 2017

As i have said i have not checked it yet and i have not saw that comment above. Needs to be tested.

@Bakual
Copy link
Contributor

Bakual commented Apr 27, 2017

Honestly, just revert #13407.

@PhilETaylor

This comment was marked as abuse.

@zero-24
Copy link
Member

zero-24 commented Apr 27, 2017

@Bakual i think the rest (array + renaming a var) can stay from that PR? Just that str_replace needs to be checked i guess.

@PhilETaylor

This comment was marked as abuse.

@brianteeman
Copy link
Contributor

You absolutely can not remove the qq processing!!

@mbabker
Copy link
Contributor

mbabker commented Apr 27, 2017

Do not revert #13407

The only thing you need to do is basically if parse_ini_file is usable then use it otherwise use our old way which supports broken INI files

  1. We need to stop allowing broken crap to work in our core APIs
  2. The simplest option is to use the simplest function if available, since apparently hosts are 3 steps past moronic we can have a sensible fallback (i.e. the old code which has been proven to work with broken files)
  3. The fact that this project is still so reluctant to accept valid third party solutions is really getting out of hand. We don't have the developers to write everything ourselves because we keep chasing everyone with half an ounce of skill away.

@infograf768
Copy link
Member

infograf768 commented Apr 27, 2017

For testers:
add
disable_functions = parse_ini_file
in your php.ini file
Stop and restart server.

@PhilETaylor

This comment was marked as abuse.

@csthomas
Copy link
Contributor

Constants for parse_ini_string() are supported in php version 5.3.2.
I have checked it at https://3v4l.org/#preview

Constants are not supported in hhvm 3.19.1 and lower at all for both (parse_ini_file, parse_ini_string)

I tested with code:

echo phpversion() . "\n";
define('__QQ__', " WORKS ");
print_r(parse_ini_string('A="IT"__QQ__"GREATE!"'));
print_r(parse_ini_file(__DIR__ . '/test.ini'));

For hhvm I got:

5.6.99-hhvm
Array
(
    [A] => IT__QQ__GREATE!
)
Array
(
    [A] => IT__QQ__GREATE!
)

@PhilETaylor

This comment was marked as abuse.

@csthomas
Copy link
Contributor

If you will add unittest for __QQ__ then you will have to:)

@Bakual
Copy link
Contributor

Bakual commented Apr 27, 2017

Afaik currently unit tests run on HHVM. But the CMS itself not necessary. To my knowledge we don't support it yet officially.

$strings = $this->inspector->parse(__DIR__ . '/data/bad.ini');
/**
* suppressor used as we know this will generate a warning message
* syntax error, unexpected BOOL_TRUE in
Copy link
Contributor

Choose a reason for hiding this comment

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

in.........

This comment was marked as abuse.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

TBH, I don't think it's even worth the effort to support HHVM anymore. Seems it is losing traction with the PHP community and big players are dropping support for it because apparently it doesn't have feature parity with PHP core starting with 5.6.

Copy link
Contributor

@csthomas csthomas Apr 28, 2017

Choose a reason for hiding this comment

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

I do not care about HVVM support but I want to enforce a unit test for _QQ_.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mbabker About my proposed changes. Would it be better to remove lines with hhvm support and allow the unit test on hhvm to fail? Or better way is to not add a unit test for _QQ_ now?

This comment was marked as abuse.

This comment was marked as abuse.

@infograf768 infograf768 added this to the Joomla 3.7.1 milestone Apr 28, 2017
@rdeutz
Copy link
Contributor

rdeutz commented May 2, 2017

Can some test this so that we can get this in 3.7.1?


if (!is_array($strings))
{
$strings = array();
Copy link
Contributor

Choose a reason for hiding this comment

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

@PhilETaylor If you are not convinced about merge my PR can you at least remove a ternary operator from line 857:

return is_array($strings) ? $strings : array();

which is equal to your new code:

if (!is_array($strings))
{
	$strings = array();
}

This comment was marked as abuse.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks

@PhilETaylor

This comment was marked as abuse.

@infograf768
Copy link
Member

I have tested this item ✅ successfully on 30e69b3


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/15620.

@AlexRed
Copy link
Contributor

AlexRed commented May 2, 2017

I have tested this item ✅ successfully on 30e69b3

Patch ok for me


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/15620.

@joomla-cms-bot joomla-cms-bot removed this from the Joomla 3.7.1 milestone May 2, 2017
@ghost
Copy link

ghost commented May 2, 2017

RTC after two successful tests.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label May 2, 2017
@rdeutz rdeutz merged commit 9b9c122 into joomla:staging May 3, 2017
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label May 3, 2017
@rdeutz rdeutz added this to the Joomla 3.7.1 milestone May 3, 2017
@MixingOnBeat
Copy link

Boy, did I also have a rough time with this update from 3.6.5 to 3.7.0. After the upgrade all the text in the admin panel as well as some text on the public pages were a mess. I also have a host/server that doesn't allow me to alter php.ini files. :(

I had to revert back my changes (glad I made a backup of the files/database). I hope you guys find a common ground for 3.7.1. I read all arguments and though it would be nice that some hosts would not do this, but as long this can be fixed using a bit of code, perhaps this is best for everyone.

@wilsonge
Copy link
Contributor

This patch got merged and we hope that 3.7.1 will drop towards the end of next week with the fix for you in :)

brianteeman pushed a commit to brianteeman/joomla-cms that referenced this pull request May 16, 2017
* Fix Language parsing when parse_ini_file disabled

closes joomla#15587

Use sensible code available in FOF to process ini files when moronic web hosts disable parse_ini_file in php.ini

Please test

* Only load FOFUtilsIniParser if needed

* Tabs not spaces

* Unit Testing

* tabs not spaces - darn editors

* TABS!

* Different approach

* remove QQ replacement (apparently its not needed)

* re-add QQ replacement (apparently its needed)

* Revert joomla#13407 almost :)

* ok back to this if/else

* Update Unit Testing

* Update Unit Testing

* remove a ternary operator
@hakanara
Copy link

hakanara commented Jun 1, 2017

Hi all, this issue is still existing with a fresh 3.7.2 installation. Shall I open a new issue?

@brianteeman
Copy link
Contributor

Yes please

@hakanara
Copy link

Fresh installation or a 3.7.3 upgrade still shows us that moronic hosting issue interferes Joomla and prevents Joomla from rocking. All Joomla loverz, let's unite and let Joomla rock!

@hakanara
Copy link

hakanara commented Jul 21, 2017

You are all invited to the reopening of #17198

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Language Files: Problem after update to 3.7