Gossamer Forum
Home : General : Perl Programming :

nonprintable characters

Quote Reply
nonprintable characters
another email issue! i have my form set up to reject if email message is less than a certain number of characters. i am receiving emails in which the message appears empty but contains nonprintable characters. how can i test for this and remove the nonprintable characters from the message. here's the parse sub:
Code:
sub parse_form {
# --------------------------------------------------------
my (%in);
my ($buffer, $pair, $name, $value,$s);
PAIR: foreach $name ($query->param()) {
@value = $query->param("$name");
$value = join '~~', @value;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$value =~ tr/+/ /;
if ($value eq "---") { next PAIR; }
if ($value eq "http://") { next PAIR; } # Removes default beginning of URLs
unless ($value =~ /\S+/) { next PAIR; } # 01/29/2017

$in{$name} = $value;
}
return %in;
}
Quote Reply
Re: [delicia] nonprintable characters In reply to
i had taken out the following line:
Code:
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
which was after:
Code:
$value =~ tr/+/ /;
i don't know why i removed it but it looks like that would solve my problem???

edit: i tried it but it still let me enter 5 consecutive nonbreaking spaces & n b s p ;

Last edited by:

delicia: Mar 3, 2021, 8:01 AM
Quote Reply
Re: [delicia] nonprintable characters In reply to
Hi,

Its hard to know. Could it be UTF8 that is breaking?

Code:
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

This converts URL encoded values (%20 for space), into proper values.

Quote:
edit: i tried it but it still let me enter 5 consecutive nonbreaking spaces & n b s p ;

Not sure what you mean?

What is $query? A CGI.pm object? Or a GT specific one? You really shouldn't have to be doing decoding of strings from the POST/GET values

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!

Last edited by:

Andy: Mar 3, 2021, 8:25 AM
Quote Reply
Re: [Andy] nonprintable characters In reply to
i don't know what you mean by utf-8 breaking.

i put back in the line
Code:
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
because i don't know why i took it out. i entered 5 nonbreaking spaces ( ) and the script treated them as sufficient characters to meet my minimum length of field requirement.

the beginning of the script has
Code:
local(%in) = &parse_form;

i don't know what $query is; i haven't messed with it.
Quote Reply
Re: [delicia] nonprintable characters In reply to
What data is being passed in? Because   IS 5 chars long. So if you wanted it to not be, you would need to decode any HTML values passed in:



https://metacpan.org/pod/HTML::Entities

Code:
use HTML::Entities;
decode_entities($value);

That would convert " " into " ", and " into "

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] nonprintable characters In reply to
that sounds like what i need. i'll give it a try. thanks!
Quote Reply
Re: [delicia] nonprintable characters In reply to
ok, it changed a bunch of   to:
=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=
it sent the email which displays the characters as black diamonds with a question mark inside. :(
Quote Reply
Re: [delicia] nonprintable characters In reply to
Sorry, it should be:

Code:
$value = decode_entities($value);

Not sure if that'll help though.

Quote:
=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=
it sent the email which displays the characters as black diamonds with a question mark inside. :(

Its really hard to debug without seeing the full code around it (and unfortunately I don't have time to look into that as I'm up to my neck already). What you have there looks more like email encoded strings. For example, %20 (space), in an email looks like =20. What does your parse_form look like now? I would try adding some debugging after each bit - so before you encode it, after you encode it, and then ahain after you use the new function. Then hopefully you can see where its breaking

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!