about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFranck Cuny <franckcuny@gmail.com>2015-07-07 11:28:18 -0700
committerFranck Cuny <franckcuny@gmail.com>2015-07-07 11:39:58 -0700
commit327df973ccdd0def50a4448a3161df8dc76b8a03 (patch)
tree23aeb36e8f20a4295ddb4442c25716685ce72e58
parentDrop Perl 5.10 from Travis (diff)
downloadplack-middleware-etag-327df973ccdd0def50a4448a3161df8dc76b8a03.tar.gz
Fix off-by-one error.
When calling the `stat` function on a file, the inode number is stored in the
second element (index 1) of the array, not the third (index 2). Instead of
getting the inode we were using the mode, which is incorrect.
-rw-r--r--lib/Plack/Middleware/ETag.pm7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/Plack/Middleware/ETag.pm b/lib/Plack/Middleware/ETag.pm
index 22dcc01..86912f4 100644
--- a/lib/Plack/Middleware/ETag.pm
+++ b/lib/Plack/Middleware/ETag.pm
@@ -35,13 +35,12 @@ sub call {
                 my $file_attr = $self->file_etag || [qw/inode mtime size/];
                 my @stats = stat $res->[2];
                 if ( $stats[9] == time - 1 ) {
-
-            # if the file was modified less than one second before the request
-            # it may be modified in a near future, so we return a weak etag
+                    # if the file was modified less than one second before the request
+                    # it may be modified in a near future, so we return a weak etag
                     $etag = "W/";
                 }
                 if ( grep {/inode/} @$file_attr ) {
-                    $etag .= ( sprintf "%x", $stats[2] );
+                    $etag .= ( sprintf "%x", $stats[1] );
                 }
                 if ( grep {/mtime/} @$file_attr ) {
                     $etag .= "-" if ( $etag && $etag !~ /-$/ );