Perl write to file returns huge weird stacktrace -


i have following problem: when try save file contains semicolon in name returns huge , weird stacktrace of characters on page. i've tried escape, trim , replace semicolons, result still same. use following regex:

$value =~ s/([^a-za-z0-9_\-.]|;)/uc sprintf("%%%02x",ord($1))/eg;

(i've added |; part separately..)

so, when open file write , call print function returns lots of weird stuff, that:

pk!}�3y�[content_types].xml ���/�h9\�?�0���cz��:� �s_����o���>�t�� (it huge one, part of it).

is there way avoid this?

thank in advance!

edit:

just interested - pk responsible of in string? mean can understand chars contents of file, pk ? , why show content type?

edit 2.0:

i'm uploading .docx file - when name doesn't contain semicolon works fine. code file saving:

open (qstr,">", "$dest_file") or die "can't open output file: $qstring_file"; print qstr $value; close (qstr); 

edit 3.0

this .cgi script, called after posting data server. has save info uploading file temp file (name, contents, size) in manner of key-value pairs. file contains semicolon causes error.

edit 4.0 found cause:

the cgi param function while uploading params counts semicolon delimiter! there way escape in file header?

the pk in file header means compressed zip file, docx.

one guess: ; not valid character in filename @ destination?

your regexp not good: (the dot alone applicable character...)

$value =~ s/([^a-za-z0-9_\-.]|;)/uc sprintf("%%%02x",ord($1))/eg; 

try this:

#replace evey non valid char underscore $value =~ s/([^a-za-z0-9_\-\.\;])/_/g; 

Comments