Previous Thread
Next Thread
Print Thread
Hop To
Joined: Oct 2006
Posts: 37
G
newbie
newbie
G Offline
Joined: Oct 2006
Posts: 37
I tested this and the bug appears to be in do_markup in ubbthreads.inc.php. The text going in is correct but coming out, it's wrong.

Text such as this in a post:
Code
http://www.example.com/page.html

results in this HTML
Code
<a href="http://www.example.com/page.html" target="_blank"></a><a href="http://www.example.com/page.html" target="_blank"></a><a href="http://www.example.com/page.html" target="_blank"></a><a href="http://www.example.com/page.html" target="_blank"></a><a href="http://www.example.com/page.html" target="_blank"></a><a href="http://www.example.com/page.html" target="_blank"></a><a href="http://www.example.com/page.html" target="_blank"></a><a href="http://www.example.com/page.html" target="_blank"></a><a href="http://www.example.com/page.html" target="_blank"></a><a href="http://www.example.com/page.html" target="_blank">http://www.example.com/page.html</a>

A similar thing happens to [ url ]link[ /url ] code (except the links are nested).

One doesn't notice because all but one of the ten links are empt y and don't show on the browser, but this needs to be fixed. Besides being untidy and wasteful in the database, Google is likely to think the page is rigged to throw off their rankings and exclude them.

I think the problem is that more than one entry in the $regexes array is hitting the same link. I think they probably need to be broken up into "run all these" and "run until one of these is found" expressions.

After looking at the code awhile, I give up. No idea why it's happening. Those regex's will drive you mad.

Last edited by Rick; 10/23/2006 11:36 AM.
Joined: Jun 2006
Posts: 9,242
Likes: 1
R
Former Developer
Former Developer
R Offline
Joined: Jun 2006
Posts: 9,242
Likes: 1
It's actually a loop that goes over the regexes that I'm not exactly sure why it's there.

Editing ubbthreads.inc.php seems to fix this. Around line 988 of that file there is a block of code that looks like this:
Code
while( $x && ( $loop < 10 ) ) {
     $loop++;
     foreach( $regexes as $z ) {
          if( preg_match( $z[0], $body ) ) { 
               $x++;
               $body = preg_replace( $z[0], $z[1], $body );
          }
     }
} // end while

We need to comment out the loop, like this:

Code
//while( $x && ( $loop < 10 ) ) {
     // $loop++;
     foreach( $regexes as $z ) {
          if( preg_match( $z[0], $body ) ) { 
               $x++;
               $body = preg_replace( $z[0], $z[1], $body );
          }
     }
//} // end while

Joined: Jun 2006
Posts: 9,242
Likes: 1
R
Former Developer
Former Developer
R Offline
Joined: Jun 2006
Posts: 9,242
Likes: 1
This fix actually breaks multi-level quotes. I've reworked the do_markup function to fix this for 7.0.1. It's a pretty major change so not one that I can post here.

Joined: Oct 2006
Posts: 37
G
newbie
newbie
G Offline
Joined: Oct 2006
Posts: 37
I've been looking at similar problems with a similar chunk of code in the migration program. I just now found the same thing, that nested items is what requires looping but some of the expressions interfere with each other.

I think the fix might be to reverse the loop so that each expression is evaluated 10 times rather than the whole batch 10 times. That will resolve all the nestings for one regex before moving to the next.

Example:

Code
foreach( $regexes as $z ) {
   for( $loop = 0; $loop < 10; $loop++ ) {
      if( !preg_match( $z[0], $body ) )
         break;
      $body = preg_replace( $z[0], $z[1], $body );
   }
}

I like the way you're checking to see if you're done with the expression rather than put up with just doing it 10 times (since we can't count on the count parameter being there in preg_replace).

Anyway, the above works so far in the migration code and still keeps the code simple, but time will tell.

Joined: Oct 2006
Posts: 37
G
newbie
newbie
G Offline
Joined: Oct 2006
Posts: 37
Sigh, nope, that brings the repeated anchor tag problem back. Nevermind. frown

Well, it's the auto-url regexes that seem to be causing it, so maybe those need moving to a one-time-only loop. That's fixed it here, so far.

Last edited by GregH; 10/25/2006 12:46 PM.
Joined: Jun 2006
Posts: 9,242
Likes: 1
R
Former Developer
Former Developer
R Offline
Joined: Jun 2006
Posts: 9,242
Likes: 1
That's what I've ended up doing for 7.0.1. I've moved all of the url regexes out of the array so they only get processed one time.

Joined: Oct 2006
Posts: 37
G
newbie
newbie
G Offline
Joined: Oct 2006
Posts: 37
Excellent, thanks.


Link Copied to Clipboard
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Recent Topics
Bots
by Outdoorking - 04/13/2024 5:08 PM
Can you add html to language files?
by Baldeagle - 04/07/2024 2:41 PM
Do I need to rebuild my database?
by Baldeagle - 04/07/2024 2:58 AM
This is not a bug, but a suggestion
by Baldeagle - 04/05/2024 11:25 PM
Is UBB.threads still going?
by Aaron101 - 04/01/2022 8:18 AM
Who's Online Now
0 members (), 868 guests, and 467 robots.
Key: Admin, Global Mod, Mod
Random Gallery Image
Latest Gallery Images
Los Angeles
Los Angeles
by isaac, August 6
3D Creations
3D Creations
by JAISP, December 30
Artistic structures
Artistic structures
by isaac, August 29
Stones
Stones
by isaac, August 19
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20230217)