Gossamer Forum
Home : Products : Links 2.0 : Discussions :

forbidden delimiter

Quote Reply
forbidden delimiter
Hi
I'm using the tube "|" delimiter in links.db
As I'm exporting links.db to another application in sql, I need to be sure that noone can enter the tube character inside any field.
Is there any kind of simple check for this?

Quote Reply
Re: forbidden delimiter In reply to
You can use regexp to change that character to a space, like the following in the sub site_html_add_success routine in the site_html_templates.pl file or in the sub process_form in the add.cgi script/modify.cgi script:

Code:

$in{'FieldName'} =~ s/\|//g;


Regards,

Eliot Lee
Quote Reply
Re: forbidden delimiter In reply to
You'd need to escape it though as | is used as "or" in regex:

Code:
$in{'FieldName'} =~ s/\|/ /g;
Installs:http://wiredon.net/gt
FAQ:http://www.perlmad.com

Quote Reply
Re: forbidden delimiter In reply to
I use no templates.
so, in add.cgi :

sub process_form {
# --------------------------------------------------------
my ($key, $status, $line, $output);

# Check the referer.
if (@db_referers and $ENV{'HTTP_REFERER'}) {
$found = 0;
foreach (@db_referers) {
$ENV{'HTTP_REFERER'} =~ /$_/i and $found++ and last;
}
if (!$found) {
&site_html_add_failure ("Auto submission is not allowed in this directory. Please visit the site to add your entry.");
return;
}
}

# This will set system fields like Validated to their proper values.
foreach $key (keys %add_system_fields) {
$in{$key} = $add_system_fields{$key};
}

# Set date variable to today's date.
$in{$db_cols[$db_modified]} = &get_date;

open (ID, "<$db_links_id_file_name") or &cgierr("error in process_form. unable to open id file: $db_links_id_file_name. Reason: $!");
$in{$db_key} = <ID> + 1; # Get next ID number
close ID;

# Validate the form input..
$status = &validate_record(%in);
if ($status eq "ok") {

# Update the counter.
open (ID, ">$db_links_id_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_links_id_file_name. Reason: $!");
flock(ID, 2) unless (!$db_use_flock);
print ID $in{$db_key}; # update counter.
close ID; # automatically removes file lock

# Print out the validate input to a "validation database" where it is stored until
# the admin decides to add it into the real database.
open (VAL, ">>$db_valid_name") or &cgierr("error in add_record. unable to open validate file: $db_valid_name. Reason: $!");
flock(VAL, 2) unless (!$db_use_flock);
print VAL &join_encode(%in);
close VAL; # automatically removes file lock

# Send the admin an email message notifying of new addition.
&send_email;
# Send the visitor to the success page.
&site_html_add_success;
}
else {
&site_html_add_failure($status);
}
}


Where do I insert this
$in{'FieldName'} =~ s/\|/ /g;
??

Quote Reply
Re: forbidden delimiter In reply to
Just above:

open (VAL, ">>$db_valid_name") or &cgierr("error in add_record. unable to open validate file: $db_valid_name. Reason: $!");[/pre]Installs:http://wiredon.net/gt
FAQ:http://www.perlmad.com

Quote Reply
Re: forbidden delimiter In reply to
WORKS GREAT!
thanx a lot


Quote Reply
Re: forbidden delimiter In reply to
Thanks, Paul...fixed it.

Regards,

Eliot Lee