Make WordPress Core

Opened 17 years ago

Closed 17 years ago

#3698 closed defect (bug) (fixed)

Matching more tags eats up too much content

Reported by: curioso's profile Curioso Owned by: nazgul's profile Nazgul
Milestone: 2.2 Priority: normal
Severity: normal Version: 2.1
Component: General Keywords: has-patch
Focuses: Cc:

Description

The preg_match('/<!--more(.+?)?-->/', $content, $matches) that is used to find the more-tag matches content up to the end of a next comment if present.
This is because while the first '?' indictaes non-greedy match, it still has to match at least one character, eting up the first '-' of '-->', and then only terminates on the end of the next comment.

Changing to preg_match('/<!--more(.*?)-->/', $post, $matches) in wordpress/wp-includes/post.php and wordpress/wp-includes/post-template.php gives the correct behaviour.

Attachments (3)

post.patch (962 bytes) - added by Viper007Bond 17 years ago.
Patch for described change + minor formatting fixes
more.patch (1.1 KB) - added by McShelby 17 years ago.
3698.diff (1.1 KB) - added by Nazgul 17 years ago.

Download all attachments as: .zip

Change History (15)

@Viper007Bond
17 years ago

Patch for described change + minor formatting fixes

#1 @markjaquith
17 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [4821]) Make <!--more--> regex non-greedy. Props Curloso and Viper007Bond. fixes #3698

#2 @markjaquith
17 years ago

(In [4822]) Make <!--more--> regex non-greedy. Props Curloso and Viper007Bond. fixes #3698

#3 @foolswisdom
17 years ago

  • Version set to 2.1

#4 follow-up: @McShelby
17 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

I am just wondering about the regex in general and the patch in specific.

Why is the regex designed to match any arbitrary character after the "more" keyword? From my point of view this only makes sense if WP wants to support XHTML styled "more" tags like <!--more/-->. At the moment I can put a HTML comment into the post like <!--more information below--> which will accidently be treated as a "more" tag.

To avoid the above and to support XHTML styled "more" tags, the regex should be changed to '<!--more\s*(?:\/)?-->/'

Also post.patch was only applied to post.php and not to post-template.php. Was this as intended?

Patch for the proposed changes to post.php and post-template.php is attached.

@McShelby
17 years ago

#5 in reply to: ↑ 4 @foolswisdom
17 years ago

Replying to McShelby:

Why is the regex designed to match any arbitrary character after the "more" keyword?

"customize the More… link for each post split by the <!--more--> tag"
http://wordpress.com/blog/2006/08/02/but-wait-theres-more/

#6 @McShelby
17 years ago

Thanks, now I get it. I can not say that this is very intuitive to me but that's just my biased opinion. Nevertheless, the regex fix from post.patch should also be applied to post-template.php. Or am I wrong again?

#7 @yskin
17 years ago

Use “123<!--more-->hoho,<!--haha-->456” in post content, $more_link_text will be “-->hoho,”.

So we can not use HTML comment after more tag?

#8 follow-up: @Nazgul
17 years ago

  • Milestone changed from 2.1.1 to 2.1.2

Yskin, I'm unable to reproduce your issue in 2.1.1.

McShelby, I think you're right about post-template.php, it needs a patch as well.

#9 in reply to: ↑ 8 @yskin
17 years ago

Replying to Nazgul:

Yskin, I'm unable to reproduce your issue in 2.1.1.

In the backend of test.edward.in, click Code tab, enter

First line.<!--more-->Second line.<!--page-->Third line.

And then publish post.

HTML in front page(http://test.edward.in/):

<p>First line. <a href="http://test.edward.in/?p=4#more-4" class="more-link">-->Second line.</a></p>

HTML in post page(http://test.edward.in/?p=4):

<p>First line.<a id="more-4"></a>Third line.</p>

Replace "<!--page-->" to "<!--nextpage-->", everything is ok. So this bug does not impact many people, because not many people will use HTML comment in post content.

#10 @foolswisdom
17 years ago

  • Milestone changed from 2.1.3 to 2.2

@Nazgul
17 years ago

#11 @Nazgul
17 years ago

  • Keywords has-patch added
  • Owner changed from anonymous to Nazgul
  • Status changed from reopened to new

#12 @rob1n
17 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [5244]) <!--more--> regex fixes. Props Nazgul. fixes #3698

Note: See TracTickets for help on using tickets.