| Ticket UUID: | 1034580 | |||
| Title: | Failure in parsing <??? /> tags | |||
| Type: | Bug | Version: | None | |
| Submitter: | petasis | Created on: | 2004-09-25 13:25:11 | |
| Subsystem: | htmlparse | Assigned To: | andreas_kupries | |
| Priority: | 5 Medium | Severity: | ||
| Status: | Closed | Last Modified: | 2004-10-01 02:36:41 | |
| Resolution: | Fixed | Closed By: | andreas_kupries | |
| Closed on: | 2004-09-29 18:18:32 | |||
| Description: |
It seems that htmlparse module failes to handle tags of
the form <tag_name attr_1=val ... />. A quick fix is the
following:
Add to line 329 of htmlparse.tcl:
# Convert the HTML string into a script.
set sub "\}\n$cmd {\\1} {/} {\\2} \{"
regsub -all -- {<([^\s>]+)\s*([^>]*)/>} $html $sub
html
set sub "\}\n$cmd {\\2} {\\1} {\\3} \{"
regsub -all -- {<(/?)([^\s>]+)\s*([^>]*)>} $html $sub
html
I simply add a new regular expression, that handles only
this special case.
George
| |||
| User Comments: |
petasis added on 2004-10-01 02:36:41:
Logged In: YES user_id=92283 Thanks for the better fix! To say the truth, my initial thought was to use a different character (u) for such a case instead of providing '/' as the second argument to the callback proc, to indicate that this is a "unary" tag, i.e. a tag that starts/ends. But then I thought that this may break existing applications. (On the other hand, these applications already break on such tags, as the closing '/' was attached to the value of the last attribute). I thought a better compromise was to not alter the '/' character, and present it only as a closing tag. I was afraid to insert a 'vitual' tag, as this would alter the length in characters of the initial html code (at least as the callback sees it), which may potentially break my applications, where I use the htmlparse module to convert tags into other stand-off annotations and then strip all html tags. And as these annotations keep character references back to the original html text, I thought I would introduce new problems :-) However, I tested the final solution (which introduces this additional tag) and my apps seem to work fine. Of course this does not mean that other applications won't break, but we can't have anything :-) The only problem I think it still remains is that anyone who wishes to seperate these "unary" tags, cannot do so... George andreas_kupries added on 2004-09-30 01:18:32: Logged In: YES user_id=75003 Committed my changes to head. andreas_kupries added on 2004-09-30 01:05:47: Logged In: YES
user_id=75003
Also note the other report about this, at
http://sourceforge.net/support/tracker.php?aid=900041
This one was without code however.
andreas_kupries added on 2004-09-30 01:00:02: Logged In: YES
user_id=75003
Ok. I changed this to use
set sub "\}\n$cmd {\\1} {} {\\2} \{\}\n$cmd {\\1} {/} {} \{"
This creates an opening tag carrying the attributes,
followed by the closing tag. The opening tag does not carry
any text data (which is correct, as the tag is empty).
This will be committed.
And while I haven't used your solution exactly as-is, thank
you for making the effort to understand the parser and
providing it in the first place. It gave me enough clues to
go from there.
andreas_kupries added on 2004-09-30 00:46:13: Logged In: YES user_id=75003 This change has one problem, IMHO. In the output of parse the empty tag, lets say <a/> looks like a closing tag, without a preceeding opening tag. This makes later checking of the nesting structure, for example by "2tree" effectively impossible as the code cannot tell anymore if the closing tag without the preceeding opening tag is truly bogus, or was generated by an empty tag, and thus ok. So IMHO it would be better to convert the empty tag into something which generates both opening and closing tag. Related question: Do you have test cases ? I am currently making some up, but if you have special tests which are important to you then please submit them. | |||
Home
Blog
Docs
Downloads
Tickets
Timeline
Branches
Tags
Wiki