DME tags with attributes cause bad text processing
Shannon Lucas - April 29, 2008 - 13:05
| Project: | Drupal Markup Engine |
| Version: | 5.x-1.0 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | jcfiala |
| Status: | active |
Jump to:
Description
I am having difficulty getting DME to work with tags that use attributes, including the tags in dme_test_module.module.
If I enter this block of code as a node body:
DME Test Page<br/>
Attribute Check:<br/>
<dme:test_all_attributes title="first title" encoding="en">Inside the check</dme:test_all_attributes><br/>
<dme:caps>Caps Letters</dme:caps>
<br/><br/>
A caps test <dme:caps>more caps</dme:caps>.
<br/><br/>
Some lorem ipsum text in between.
<br/><br/>
And a second <dme:caps>all caps test</dme:caps>.
<br/><br/>
<dme:test_all_attributes title="test title" length="3">Inside the second attrcheck</dme:test_all_attributes>I get this output:
DME Test Page
Attribute Check:
[dme_inner_text=>Inside the second attrcheck|title=>test title|encoding=>en|length=>3|nid=>9442]I added an output in the 'prepare' section of dme_filter, and I see this output using the node body above:
DME Test Page
Attribute Check:
[dme:test_all_attributes title="first title" encoding="en"]Inside the check[/dme:test_all_attributes]
[dme:caps]Caps Letters[/dme:caps]
A caps test [dme:caps]more caps[/dme:caps].
Some lorem ipsum text in between.
And a second [dme:caps]all caps test[/dme:caps].
[dme:test_all_attributes title="test title" length="3"]Inside the second attrcheck[/dme:test_all_attributes]If I remove the attributes from the dme:test_all_attributes elements, I get different behavior. Using this block of code:
DME Test Page<br/>
Attribute Check:<br/>
<dme:test_all_attributes>Inside the check</dme:test_all_attributes><br/>
<dme:caps>Caps Letters</dme:caps>
<br/><br/>
A caps test <dme:caps>more caps</dme:caps>.
<br/><br/>
Some lorem ipsum text in between.
<br/><br/>
And a second <dme:caps>all caps test</dme:caps>.
<br/><br/>
<dme:test_all_attributes>Inside the second attrcheck</dme:test_all_attributes>I get this output:
DME Test Page
Attribute Check:
[dme_inner_text=>Inside the check|nid=>9442]
CAPS LETTERS
A caps test MORE CAPS.
Some lorem ipsum text in between.
And a second ALL CAPS TEST.
[dme_inner_text=>Inside the second attrcheck|nid=>9442]And this is the value of the text in the 'prepare' section of
dme_filter:DME Test Page
Attribute Check:
[dme:test_all_attributes]Inside the check[/dme:test_all_attributes]
[dme:caps]Caps Letters[/dme:caps]
A caps test [dme:caps]more caps[/dme:caps].
Some lorem ipsum text in between.
And a second [dme:caps]all caps test[/dme:caps].
[dme:test_all_attributes]Inside the second attrcheck[/dme:test_all_attributes]
#1
Hmmm. I'll have to take a look at that soon.
#2
This may be a duplicate of #249391: Greedy regex mangles successive tags.
#3
It's not a duplicate - this one I was able to reproduce pretty quickly.
I'm able to fix it, as long as I change the second regular expression in _dme_process_text from
"@\[dme:(". implode('|', $tag_name_list) .')\s*((?:\s+\w+=([-+]?[0-9.]+|(["\']).+\4))*)\s*\](?!.*\[dme:\1.*\[/dme:\1\])(.*)\[/dme:\1\]@isU'
to
"@\[dme:(". implode('|', $tag_name_list) .')\s*((?:\s+\w+=([-+]?[0-9.]+|(["\'])[^\]]+\4))*)\s*\](?!.*\[dme:\1.*\[/dme:\1\])(.*)\[/dme:\1\]@isU'
Which is a bit of a puzzle - the final U is supposed to make all of the matches non-greedy, but it isn't - it's grabbing far too much.
The problem with this fix, however, is that it prevents anyone from using a ] character in any attribute values. That's not a huge problem, I guess, but it seems really inelegant. Anyone have any ideas?