Skip to content

Commit 47b9835

Browse files
simbabqueoalders
authored andcommitted
mech-dump treats all local files as HTML
Fixes #63 Closes #102
1 parent 8fbe02b commit 47b9835

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

Changes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Revision history for WWW::Mechanize
2020
[FIXED]
2121
- tick() can now handle checkboxes without a value (GH#331) (Jordan M Adler
2222
and Julien Fiegehenn)
23+
[ENHANCEMENTS]
24+
- mech_dump now treats all local files like HTML regardless of what it
25+
thinks their content types are (GH#63) (Julien Fiegehenn)
2326

2427
[ENHANCEMENTS]
2528
- set_fields() and submit_form(with_fields => ...) can now set multiple

script/mech-dump

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ Options:
7272
The order of the options specified is relevant. Repeated options
7373
get repeated dumps.
7474
75+
C<mech-dump> will only work on HTML documents when used on remote URLs, but
76+
will assume any local file you pass it is HTML. If it is not, there won't be
77+
any usable results.
78+
7579
Proxy settings are specified through the environment (e.g. C<http_proxy=http://proxy.my.place/>).
7680
See L<LWP::UserAgent> for details.
7781
@@ -101,9 +105,11 @@ else {
101105

102106
$mech->env_proxy();
103107
foreach my $uri (@uris) {
108+
my $no_ct_check;
104109
if ( -e $uri ) {
105110
require URI::file;
106111
$uri = URI::file->new_abs( $uri )->as_string;
112+
$no_ct_check = 1; # we don't have to check the content type
107113
}
108114

109115
my $response = $mech->get( $uri );
@@ -115,7 +121,10 @@ foreach my $uri (@uris) {
115121
$response = $mech->get( $uri );
116122
$response->is_success or die "Can't fetch $uri with username and password\n", $response->status_line, "\n";
117123
}
118-
$mech->is_html or die qq{$uri returns type "}, $mech->ct, qq{", not "text/html"\n};
124+
125+
unless ($no_ct_check) {
126+
$mech->is_html or die qq{$uri returns type "}, $mech->ct, qq{", not "text/html"\n};
127+
}
119128

120129
foreach my $action (@actions ) {
121130
$action->( $mech );

t/html_file.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
<body>
3+
<form name="text-form" action="http://localhost">
4+
<input type="text" name="one" />
5+
</form>
6+
</body>
7+
</html>

t/mech-dump/mech-dump.t

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if ( $^O eq 'VMS' ) {
2121

2222
# Simply use a file: uri instead of the filename to make this test
2323
# more independent of what URI::* thinks.
24-
my $source = 'file:t/google.html t/find_inputs.html';
24+
my $source = 'file:t/google.html t/find_inputs.html t/html_file.txt';
2525

2626
my $perl;
2727
$perl = $1 if $^X =~ /^(.+)$/;
@@ -57,6 +57,9 @@ POST http://localhost/ [3rd_form]
5757
YourSister= (text)
5858
YourSister= (text)
5959
submit=Submit (submit)
60+
61+
GET http://localhost [text-form]
62+
one= (text)
6063
EOF
6164
} else {
6265
$expected = <<'EOF';
@@ -85,6 +88,9 @@ POST http://localhost/ [3rd_form]
8588
YourSister= (text)
8689
YourSister= (text)
8790
submit=Submit (submit)
91+
92+
GET http://localhost [text-form]
93+
one= (text)
8894
EOF
8995
}
9096

0 commit comments

Comments
 (0)