| 1 | package HTML::FormRemove; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # -*- Perl -*- Tue May 21 13:01:01 CDT 2002 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Written by Tim Skirvin <tskirvin@ks.uiuc.edu> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Copyright 2000-2002, Tim Skirvin and UIUC Board of Trustees. Redistribution | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # terms are below. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | $VERSION = "0.3a"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | HTML::FormRemove - remove form tags from HTML | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | my $html = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | "<FORM> <INPUT TYPE=TEXT NAME='Test' VALUE='Hello World!'> </FORM>"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | use HTML::FormRemove | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | print RemoveFormValues($html); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | HTML::FormRemove is a module that removes form tags from HTML, while | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | otherwise leaving the HTML intact. This allows for forms to be converted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | into something printable and usable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | use HTML::Form; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | use vars qw( @EXPORT @EXPORT_OK @ISA ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | @ISA = "Exporter"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | @EXPORT = qw( RemoveFormValues ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # Untaint $0; this may not be the best idea in the world, but it's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # necessary if we're in taint mode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | if ($0 =~ /^(.*)$/) { $0 = $1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | =item RemoveFormValues ( HTML [, HTML [, HTML [...]]] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | Removes the form values. Exported by default. Returns an array of lines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | containing the updated HTML, or one single like containing them separated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | by newlines. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # We want to modularize this a lot, and fix it up. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub RemoveFormValues { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
RemoveFormValues: not called CC=18 SCAR=58.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $line = join("\n", @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | return undef unless $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $form = HTML::Form->parse($line, $0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # Take out the <form> and </form> tags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $line =~ s%</?form[^>]*>%%isg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # Take out <textarea> and </textarea>, replacing them with <pre>[...]</pre> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # (this may not be the best idea; perhaps we should just leave them in?) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $line =~ s%<(\s*/?\s*)textarea([^>]*)*>%<$1pre$2>%g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my (%radio); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # Take out <input ...> bits, leaving the 'value' part, unless it's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # a 'submit' box, in which case we'll drop it entirely | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | my $i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $line =~ s%(<input[^>]*>)% | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $form = HTML::Form->parse("<form>$1</form>", $0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | foreach ($form->inputs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | next unless ref $_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $i = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ($_->type eq 'submit' || $_->type eq 'reset') { } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
Condition0%0/3
$_->type eq "submit" or $_->type eq "reset"
MC/DC0%0/2
$_->type eq "submit" or $_->type eq "reset"
$_->type eq "submit"
$_->type eq "reset"
Truth table0%0/3
A or B
A= $_->type eq "submit"B= $_->type eq "reset"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ▶ | elsif ($_->type eq 'image' || $_->type eq 'button' ) { } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_->type eq "image" or $_->type eq "button"
MC/DC0%0/2
$_->type eq "image" or $_->type eq "button"
$_->type eq "image"
$_->type eq "button"
Truth table0%0/3
A or B
A= $_->type eq "image"B= $_->type eq "button"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | elsif ($_->type eq 'radio') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $input = $form->find_input($_->name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($input->value) { $i = " [X] " unless $radio{$_->name}++ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | else { $i = " [ ] " } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | elsif ($_->type eq 'checkbox') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $input = $form->find_input($_->name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | $input->value ? $i = " [X] " : $i = " [ ] "; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | elsif ($_->type eq 'hidden') { } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | elsif ($_->type eq 'file') { } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | elsif ($_->type eq 'password') { $i = $_->value; $i =~ s/./x/g; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | elsif ($_->type eq 'text') { $i = $_->value } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | else { $i = ""} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $i %eisgx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # Now comes the work with 'select'. Just leave these in a form tag. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $line =~ s%(<select[^>]*>.*</select[^>]*>)% | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | "<form>$1</form>" %eisgx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | wantarray ? split("\n", $line) : $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | =head1 NOTES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | This module is a work in progress; I've only got basic functionality | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | working at the moment. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | =head1 REQUIREMENTS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | Perl 5 or better, and the C<HTML::Form> module (with everything that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | requires). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | B<HTML::Form> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | http://www.ks.uiuc.edu/Development/MDTools/dbiframe for the latest version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | =head1 TODO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | Modularize the code. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | Make some more specific functions, and allow for more customizability | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | within it. IE, it'd be nice to only take out <textarea> tags, and leave | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | everything else alone. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | Written by Tim Skirvin <tskirvin@ks.uiuc.edu>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | University of Illinois Open Source License | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | Copyright (c) 2002 University of Illinois Board of Trustees | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | All rights reserved | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | Developed by: Theoretical Biophysics Group | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | University of Illinois, Beckman Institute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | http://www.ks.uiuc.edu/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | Permission is hereby granted, free of charge, to any person obtaining a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | copy of this software, DBI::Frame, and associated documentation files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | (the "Software"), to deal with the Software without restriction, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | including without limitation the rights to use, copy, modify, merge, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | publish, distribute, sublicense, and/or sell copies of the Software, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | to permit persons to whom the Software is furnished to do so, subject to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | the following conditions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | * Redistributions of source code must retain the above copyright | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | notice, this list of conditions and the following disclaimers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | * Redistributions in binary form must reproduce the above copyright | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | notice, this list of conditions and the following disclaimers in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | the documentation and/or other materials provided with the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | distribution. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | * Neither the names of the Theoretical Biophysics Group, the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | University of Illinois, nor the names of its contributors may | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | be used to endorse or promote products derived from this Software | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | without specific prior written permission. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | OTHER DEALINGS WITH THE SOFTWARE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | Copyright 2001-2002 by the University of Illinois Board of Trustees and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | Tim Skirvin <tskirvin@ks.uiuc.edu>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | ##### Version History | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # v0.1a Fri Jun 15 15:05:10 CDT 2001 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | ### Initial version. Works, but not all that well. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # v0.2a Thu Feb 21 11:24:02 CST 2002 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | ### Changed to UIUC/NCSA Open Source License. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # v0.3a Tue May 21 11:22:37 CDT 2002 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | ### Made the <textarea> filtering easier, and works properly. Fixed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | ### interaction with URI and taint mode by untainting $0. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||