Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: Gus A on January 20, 2022, 08:56:23 AM

Title: 2.0.18 -> 2.0.19: QueryString.php Test Failed
Post by: Gus A on January 20, 2022, 08:56:23 AM
Hey folks. Hope everyone is doing well. Just tried to apply this update and I get a "Test failed" error for ./Sources/QueryString.php

When I click on the edit icon on the left I get this message (see attached screenshot).

I'm assuming that I need to find this line of code

if (strpos($m[0], $context['session_var']) === false)

And replace it with this.

if (!empty($context['session_var']) && strpos($m[0], $context['session_var']) === false)
The only problem is that I can't find that first line in the QueryString.php file.

Am I missing something?

Screen Shot 2022-01-20 at 8.48.41 AM.png

Title: Re: 2.0.18 -> 2.0.19: QueryString.php Test Failed
Post by: Doug Heffernan on January 20, 2022, 09:54:40 AM
Can you attach the file in question here?
Title: Re: 2.0.18 -> 2.0.19: QueryString.php Test Failed
Post by: Gus A on January 20, 2022, 10:24:38 AM
Quote from: Doug Heffernan on January 20, 2022, 09:54:40 AMCan you attach the file in question here?

Here you go!

QueryString.php
Title: Re: 2.0.18 -> 2.0.19: QueryString.php Test Failed
Post by: Kindred on January 20, 2022, 10:57:05 AM
https://wiki.simplemachines.org/smf/Error_in_mod_installation
Title: Re: 2.0.18 -> 2.0.19: QueryString.php Test Failed
Post by: Doug Heffernan on January 20, 2022, 12:30:28 PM
Quote from: Kindred on January 20, 2022, 10:57:05 AMhttps://wiki.simplemachines.org/smf/Error_in_mod_installation

As mentioned above, the OP can not find the code mentioned in the error message.

Quote from: Gus A on January 20, 2022, 10:24:38 AM
Quote from: Doug Heffernan on January 20, 2022, 09:54:40 AMCan you attach the file in question here?

Here you go!

QueryString.php


You are right. The code mentioned in the error message does not exist. Anyways, find this code:

// This should work even in 4.2.x, just not CGI without cgi.fix_pathinfo.
if (!empty($modSettings['queryless_urls']) && (!$context['server']['is_cgi'] || @ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && ($context['server']['is_apache'] || $context['server']['is_lighttpd']))
{
// Let's do something special for session ids!
if (defined('SID') && SID != '')
$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic|page)=[^#"]+?)(#[^"]*?)?"~', 'sid_insert__preg_callback', $buffer);
else
$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic|page)=[^#"]+?)(#[^"]*?)?"~', 'pathinfo_insert__preg_callback', $buffer);
}

And add below:

// Be nice and try to inject session tokens into login forms since many older themes don't.
if ($user_info['is_guest'])
$buffer = preg_replace_callback(
'~(<form[^<]+action=login2(.+))</form>~iUs' . (!empty($context['utf8']) ? 'u' : ''),
function ($m) use ($context)
{
$repl = '';
if (!empty($context['session_var']) && strpos($m[0], $context['session_var']) === false)
$repl .= '<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '"/>';

return $m[1] . $repl . '</form>';
},
$buffer
);

Save the changes and you should be all set. Or better yet, reupload said file in question with that of the 2.0.19 upgrade package. If you have made manual edits to the file, you will have to re-add them again. Hope it helps.
Title: Re: 2.0.18 -> 2.0.19: QueryString.php Test Failed
Post by: Kindred on January 20, 2022, 01:33:14 PM
Quote from: Doug Heffernan on January 20, 2022, 12:30:28 PMAs mentioned above, the OP can not find the code mentioned in the error message.


Well, yes, but that's why the automatic part failed -- the manual part is finding the code (which was probably modified by a mod) and use human logic to apply...

If that entire section of code is missing, that begs the question WHY it is missing in a core file
Title: Re: 2.0.18 -> 2.0.19: QueryString.php Test Failed
Post by: Doug Heffernan on January 20, 2022, 01:42:14 PM
Quote from: Kindred on January 20, 2022, 01:33:14 PMWell, yes, but that's why the automatic part failed -- the manual part is finding the code (which was probably modified by a mod) and use human logic to apply...

If that entire section of code is missing, that begs the question WHY it is missing in a core file

Nope, that part of the code was not modified by a mod, but it was completely missing. That part of the code mentioned in the error message should have been there.

That is based upon checking the file that the OP attached btw. I have not checked the original file from the 2.0.18 package. If the OP has installed a mod that removes that part, it is entirely a different matter then.
Title: Re: 2.0.18 -> 2.0.19: QueryString.php Test Failed
Post by: Gus A on January 20, 2022, 02:41:41 PM
Gentlemen, this worked like a charm. Can't thank you enough for the help!

Title: Re: 2.0.18 -> 2.0.19: QueryString.php Test Failed
Post by: Doug Heffernan on January 20, 2022, 05:07:54 PM
Quote from: Gus A on January 20, 2022, 02:41:41 PMGentlemen, this worked like a charm. Can't thank you enough for the help!



Glad to have been of help.