Meaty Monks,

Follow up to this question - my Perl script uses HTML::Entities to encode form input for sql sanitization on fields like fname, lname, email, address1, etc.

I asked the question above after noticing that the at-sign (@) and the period (.) were not being encoded. I thought maybe these were not in the default list %char2entity.

So I did this (only the pertinent lines shown):

use HTML::Entities; use HTML::Entities qw( %char2entity %entity2char ); #thanks ikegami foreach $val (keys %char2entity) { print "<br>$val => $char2entity{$val}\n"; } $string = "this is an @ AT"; $string_2 = "é â ä à å ç ê ë è ï î ì Ä å É æ Æ ô ö ò û ù ÿ Ö Ü £ ¥ P ƒ + á í ó ú ñ Ñ ª º ¿ ¬ ¬ ½ ¼ ¡ @ . , < > [ ] { } - _ ; :"; print "<p>encoded @ => ".encode_entities('@').", <br>and the string ha +s become => ".encode_entities($string)." <br>and the string_2 has bec +ome => ".encode_entities($string_2)."\n";

This outputs (looking at the source of the html page returned):

... <br>@ => &#64; ... <br>. => &#46; ... encoded @ => @, <br>and the string has become => this is an @ AT <br>and the string_2 has become => &eacute; &acirc; &auml; &agrave; &a +ring; &ccedil; &ecirc; &euml; &egrave; &iuml; &icirc; &igrave; &Auml; + &aring; &Eacute; &aelig; &AElig; &ocirc; &ouml; &ograve; &ucirc; &ug +rave; &yuml; &Ouml; &Uuml; &pound; &yen; P &#131; &aacute; &iacute; & +oacute; &uacute; &ntilde; &Ntilde; &ordf; &ordm; &iquest; &not; &not; + &frac12; &frac14; &iexcl; @ . , &lt; &gt; [ ] { } - _ ; :
And I get the same result running this by telnet to ensure I'm not looking at interpreted output.

The @ and the . are right there in the hash of characters to encode. But they are not encoded. Note that several other characters that I also found in the hash are not encoded, such as [ and ].

What the heck?

Thanks.




Forget that fear of gravity,
Get a little savagery in your life.

In reply to HTML::Entities not encoding @ or . by punch_card_don

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.