Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: kuklovod - joulukuu 07, 2005, 03:39:54 AP

Otsikko: Installing mods: search does not find (a == b)
Kirjoitti: kuklovod - joulukuu 07, 2005, 03:39:54 AP
Ok, so I wasted like 4 hours on this problem: somehow search function is not able to find ==, in context "if (a == b) {}". No matter what I try - reverse=true or uninstall.xml, it just fails. Replace (a == b) with (a==b), works fine. It's not tabs or anything, two simple space characters.

Is this a known problem, should not it be documented? Really frustrating to spend time on silly things like that :)
Otsikko: Re: Installing mods: search does not find (a == b)
Kirjoitti: Dannii - joulukuu 07, 2005, 04:23:38 AP
I've never had any problems like this. Can you please explain more precisely what you were searching for?
Otsikko: Re: Installing mods: search does not find (a == b)
Kirjoitti: kuklovod - joulukuu 07, 2005, 07:12:57 AP
ok i made a mod that had this operation among others:


<operation>
<search position="replace"><![CDATA[
</td></tr>';
]]></search>
<add><![CDATA[
</td></tr>';
if ($context['is_sticky'] && ($message['id'] == $context['topic_first_message'])) {
echo '<tr><td class="titlebg" style="padding: 3px 0px;"></td></tr>';
}
]]></add>
</operation>


It was installing but reverse (uninstall) failed because it was not able to find "$message['id'] == $context['topic_first_message']", modifying it to "$message['id']==$context['topic_first_message']" fixed the problem. single = worked as well...

Replace instead of before there is simply because I was trying to find the reason for that failure, it didn't work with "before" as well. It is a search problem, most definitely.
Otsikko: Re: Installing mods: search does not find (a == b)
Kirjoitti: Dannii - joulukuu 07, 2005, 07:23:46 AP
What else is happening? You'll need a better search key than just </td></tr>'; The search part has to be unique.
Otsikko: Re: Installing mods: search does not find (a == b)
Kirjoitti: kuklovod - joulukuu 07, 2005, 07:27:06 AP
nothing else. this string is unique for the file it's being searched in. again, it is a reduced version of the search pattern i used originally, because I was trying to narrow down the problem. if you try this operation on Themes/<theme>/Display.template.php and then will try to reverse it, you will get a failure. if you replace " == " with "==", it will pass.
Otsikko: Re: Installing mods: search does not find (a == b)
Kirjoitti: Dannii - joulukuu 07, 2005, 07:29:31 AP
If you're sure that string is unique, and if that's the only operation then I can't see why it wouldn't work.
Otsikko: Re: Installing mods: search does not find (a == b)
Kirjoitti: kuklovod - joulukuu 07, 2005, 07:35:32 AP
No, there are other operations, but they are in different files/places, and they are all successfull. This operation alone was causing all the trouble, and I narrowed it down to the exact cause - " == " not being found.

Stranger yet - I can't reproduce it with simple (a == b) cases, but the original fails every time - so it's a combination of things :( This code can't be uninstalled, so you can test it:

<?xml version="1.0"?>
<!DOCTYPE modification SYSTEM "http://www.simplemachines.org/xml/modification">

<modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
<id>bug with search</id>
<version>1.0</version>

<file name="$themedir/Display.template.php">
   <operation>
   <search position="replace"><![CDATA[
   </td></tr>';
   ]]></search>
   <add><![CDATA[
   </td></tr>';
   if ($context['is_sticky'] && ($message['id'] == $context['topic_first_message'])) {
      // anything
   }
   ]]></add>
   </operation>
</file>
</modification>