substituting an exact negated string: can I? 
Author Message
 substituting an exact negated string: can I?

Hello,

I want to get rid of anything between < and > from form data unless it is a
hyperlink.
Taking from this form parser (asterisks showing the line I want to modify):

sub Parse_Form {
 if ($ENV{'REQUEST_METHOD'} eq 'GET') {

    $ENV{'QUERY_STRING'});
 } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
  read (STDIN, $buffer,
    $ENV{'CONTENT_LENGTH'});

  if ($ENV{'QUERY_STRING'}) {


   }
 } else {
  print "Content-type: text/html\n\n";
  print "<P>Use Post or Get";
 }


  ($key, $value) = split (/=/, $pair);
  $key =~ tr/+/ /;
  $key =~ s/%([a-fA-F0-9][a-fA-F0-9])/
    pack("C", hex($1))/eg;
  $value =~ tr/+/ /;
  $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/
    pack("C", hex($1))/eg;

  $value =~s/<!--(.|\n)*-->//g;   #
*****************************************************

  if ($formdata{$key}) {
   $formdata{$key} .= ", $value";
  } else {
   $formdata{$key} = $value;
  }
 }

Quote:
}

1;

I want to change the line:  $value =~ s/<!--(.|\n)*-->//g; (shown by
asterisks) to something like the following:

$value =~ s/<[^a href]*?>//gi;

The only problem is that the substitution is looking for any one of the
letters: a, space, h, r, e, and f.  It won't allow me to substitute a
negated string of this form.  Is there a way to negate 'a href' without the
brackets?  How else might I go about this?  The goal is to remove any HTML
and SSI except for hyperlinks that a person may enter into a form.  I know I
can see if I can match something I don't want in the form data and tell the
user not to do that but I would rather have the script remove it.

Thanks for any help you can offer.

-Mike Morgan



Fri, 29 Jun 2001 03:00:00 GMT  
 substituting an exact negated string: can I?
#!/usr/bin/perl

require 5.003;
use strict;

my $yes = qq(blah <img src="http://kistler.discordia.ch/x.jpg"> blah);
my $no  = qq(blah <a href="http://kistler.discordia.ch/">Unix</a> blah);

for my $try ( $yes, $no ){
        $try =~ s(<(?!a href|/a).*?>)
                 ( "removed here" )gi;
        print $try,"\n";

Quote:
}

Per.

Quote:
> I want to get rid of anything between < and > from form data unless it is a
> hyperlink.
> I want to change the line:  $value =~ s/<!--(.|\n)*-->//g; (shown by
> asterisks) to something like the following:

> $value =~ s/<[^a href]*?>//gi;

> -Mike Morgan

--

------------------------------------------------------------


Sat, 30 Jun 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. split and substitute, substitute, substitute

2. negating a string in a regexp

3. Regular Expressions: Negating bracketed strings

4. string comparison - exact matching...

5. Exact string matches

6. Substituting many strings in one pass over the input

7. Substituting many sparsely distrbuted strings in many files

8. substituting strings in source trees?

9. Pattern Match - substitute a string after the match

10. Repeat string matching/substituting ?

11. substituting string of text

12. substitute a string in array

 

 
Powered by phpBB® Forum Software