[Date Index][Thread Index]
[Date Prev][Date Next][Thread Prev][Thread Next]

Re: Strange bug in mp4h parsing



On Mon, Dec 24, 2001 at 03:39:57AM +0100, Axel Beckert wrote:
> Hi!
> 
> I've got a strange parsing bug in mp4h (wml 2.0.7, system details at
> the end of the email...):
> 
> If I use a <subst-in-string> inside a <define-tag> to make recursive
> tag definitions, <subst-in-string> seems to require a space after the
> first parameter and doesn't work, if there immediately follows a
> newline after the first parameter. Maybe there are some more pedantic
> circumstances necessary to reproduce this bug, but at least I could
> reduce the complexity to the following to examples work the difference
> out:
> 
> ---8<---
> # Doesn't work
> <define-tag add_foo whitespace=delete>
> <subst-in-string
>     "=LT=define-tag %0-only endtag=required>[%0:%%body:%0]=LT=/define-tag>"
>     "=LT=" "<" />
> </define-tag>
> 
> <add_foo bar />
> 
> <bar-only>baz</bar-only>
> 
> # Works fine
> <define-tag add_foo whitespace=delete>
> <subst-in-string
>     "=LT=define-tag %0-only endtag=required>[%0:%%body:%0]=LT=/define-tag>" 
>     "=LT=" "<" />
> </define-tag>
> 
> <add_foo bar />
> 
> <bar-only>baz</bar-only>
> --->8---
> 
> Please note the blank behind the second '=LT=/define-tag>"'! The result
> of this piece of WML code is:
> 
> ---8<---
> =LT=define-tag bar-only endtag=required>[bar:%body:bar]=LT=/define-tag>=LT=
> <bar-only>baz</bar-only>
> [bar:baz:bar]
> --->8---

Hi Axel,

this piece of code looks indeed strange, let me explain what happens.
The culprit is the `whitespace=delete' attribute, because it tries to
remove all whitespace not enclosed in tags.  To do so, body macro is
parsed to find left and right angle brackets, and whitespace is removed
when balanced brackets are found.  Unfortunately, quotes are not taken
into account, thus
  <subst-in-string
      "=LT=define-tag %0-only endtag=required>[%0:%%body:%0]=LT=/define-tag>" 
      "=LT=" "<" />
is changed into
  <subst-in-string
      "=LT=define-tag %0-only endtag=required># Metch left angle bracket
[%0:%%body:%0]=LT=/define-tag>""=LT=""<"/>

Now, is it the desired behaviour?  Obviously not, but I am not sure
being able to provide a robust solution, I have to think about it.
In the meantime, you may use balanced brackets, e.g. with

  <subst-in-string
      "<subst-define-tag %0-only endtag=required>[%0:%%body:%0]</subst-define-tag>" 
      "subst-define-tag" "define-tag" />

Thanks for your report.

-- 
Denis Barbier
WML Maintainer
______________________________________________________________________
Website META Language (WML)                www.engelschall.com/sw/wml/
Official Support Mailing List                   sw-wml@engelschall.com
Automated List Manager                       majordomo@engelschall.com