Opened 17 years ago
Closed 17 years ago
#3698 closed defect (bug) (fixed)
Matching more tags eats up too much content
Reported by: | Curioso | Owned by: | 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)
Change History (15)
#4
follow-up:
↓ 5
@
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.
#5
in reply to:
↑ 4
@
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
@
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
@
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:
↓ 9
@
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
@
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.
Patch for described change + minor formatting fixes