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

A. Pagaltzis pagaltzis at gmx.de
Wed Oct 18 16:18:44 CEST 2006


* 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,
-- 
#Aristotle
*AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
&Just->another->Perl->hacker;



More information about the Html-widget mailing list