Discussion:
[Mason-devel] HTML::Mason::FakeApache patch for unparsed_uri, etc.
Daniel Ringwalt
2007-11-28 02:57:52 UTC
Permalink
This patch to HTML/Mason/FakeApache.pm:

1. has a working unparsed_uri()
2. has uri() and unparsed_uri() return the same value they would under
Apache::RequestRec
3. has a working filename()

for Mason components running under HTML::Mason::CGIHandler.

--- orig/FakeApache.pm
+++ new/FakeApache.pm
@@ -13,6 +13,7 @@
# In the future we'll probably want to switch this to Apache::Fake or similar

use HTML::Mason::MethodMaker(read_write => [qw(query)]);
+use HTML::Mason::Tools 'taint_is_on';

sub new {
my $class = shift;
@@ -75,11 +76,27 @@
sub uri {
my $self = shift;

- $self->{uri} ||= $self->{query}->script_name . $self->path_info || '';
+ return $self->{uri} if $self->{uri};
+ if (taint_is_on()) {
+ return $self->{query}->path_info();
+ }
+ $self->{uri} = $ENV{SCRIPT_URL};
}

-# Is this available in CGI?
-# sub filename {}
+sub unparsed_uri {
+ my $self = shift;
+
+ return $self->{unparsed_uri} if $self->{unparsed_uri};
+ if (taint_is_on()) {
+ return( $self->{unparsed_uri} = $self->uri . ($self->{query}
+ ->query_string and '?' . $self->{query}->query_string) );
+ }
+ $self->{unparsed_uri} = $ENV{REQUEST_URI};
+}
+
+sub filename {
+ $_[0]->{path_translated} ||= $_[0]->{query}->path_translated();
+}

# "The $r->location method will return the path of the
# <Location> section from which the current "Perl*Handler"
Dave Rolsky
2007-12-02 21:10:42 UTC
Permalink
Post by Daniel Ringwalt
1. has a working unparsed_uri()
2. has uri() and unparsed_uri() return the same value they would under
Apache::RequestRec
3. has a working filename()
This looks pretty good. Is the reason for doing something different under
taint mode that %ENV is not available, or just that it's tainted? If it's
the latter, it'd be best to just untaint the value rather than having a
separate code path.

Also, some tests for this would be really helpful. I think in this case
it'd be sufficient to patch t/14-cgi.t, rather than the live tests. I can
update the live tests once you've done that.


-dave

/*===================================================
VegGuide.Org www.BookIRead.com
Your guide to all that's veg. My book blog
===================================================*/

Loading...