[Html-widget] HTML::Element bug (was Re: Bug in HTML::Widget::Constraint::In)

Bernhard Graf html-widget at augensalat.de
Wed Oct 18 16:27:51 CEST 2006


On Wednesday 18 October 2006 16:18, A. Pagaltzis wrote:
> * Bernhard Graf <html-widget at augensalat.de> [2006-10-18 14:45]:
> > sub _xml_escape {  # DESTRUCTIVE (a.k.a. "in-place")
> >   local $_;
>
> You don’t need to localise `$_` there as `foreach` will only
> alias it anyway. (In fact `for($var)` should be preferred over
> `local $_ = $var` for reasons having to do with not breaking any
> magic associated with the previous `$_` or `*_`.)
>
> >   foreach (@_) {
> >     s/&/&amp;/go;
> >     s/</&lt;/go;
> >     s/>/&gt;/go;
> >     s/"/&quot;/go;
>
> The `/o` switches do nothing here. Also, generally, don’t use
> `/o`.
>
> You also need to escape single quotes in order for this to be
> complete. Since `&apos;` is only defined for XML and derivatives
> but not for HTML, it’s safer to use `&#39;`. It’s shorter, too.
>
> What I end up doing is this:
>
>      s[ ([&"']) ]{ '&#' . ord( $1 ) . ';' }xge;
>      s[   <     ][&lt;]xg;
>      s[   >     ][&gt;]xg;
>
> >   }
> >   return;
> > }
>
> Regards,

-- 
Bernhard Graf



More information about the Html-widget mailing list