Skip to content

Dancer2::FileUtils::normalize path returns unexpected results for "../../.." #1102

Description

@dboehmer

I am writing a Dancer2 app with a 3rd level Perl namespace (Foo::Bar::MyApp). To retrieve a file from my projects root directory I tried to use path( dirname( __FILE__), qw<.. .. .. foo bar.baz> ) but didn't get the expected result.

After some debugging this test file shows how normalize_path is behaving differently from what I expected:

#!/usr/bin/env perl

use Test::More;

BEGIN { use_ok 'Dancer2::FileUtils', qw<normalize_path> }

sub is_path {
    my ( $input => $expected ) = @_;
    is normalize_path($input) => $expected, "$input => $expected";
}

is_path "/a/b/c/d/A/B/C"             => "/a/b/c/d/A/B/C";
is_path "/a/b/c/d/../A/B/C"          => "/a/b/c/A/B/C";
is_path "/a/b/c/d/../../A/B/C"       => "/a/b/A/B/C";
is_path "/a/b/c/d/../../../A/B/C"    => "/a/A/B/C";
is_path "/a/b/c/d/../../../../A/B/C" => "/A/B/C";

done_testing;

Output for me on Linux with Dancer2 0.166000:

normalize_path.t ..
ok 1 - use Dancer2::FileUtils;
ok 2 - /a/b/c/d/A/B/C => /a/b/c/d/A/B/C
ok 3 - /a/b/c/d/../A/B/C => /a/b/c/A/B/C
ok 4 - /a/b/c/d/../../A/B/C => /a/b/A/B/C
not ok 5 - /a/b/c/d/../../../A/B/C => /a/A/B/C
not ok 6 - /a/b/c/d/../../../../A/B/C => /A/B/C
1..6

#   Failed test '/a/b/c/d/../../../A/B/C => /a/A/B/C'
#   at catfile.pl line 9.
#          got: '/a/b/c/A/B/C'
#     expected: '/a/A/B/C'

#   Failed test '/a/b/c/d/../../../../A/B/C => /A/B/C'
#   at catfile.pl line 9.
#          got: '/a/b/A/B/C'
#     expected: '/A/B/C'
# Looks like you failed 2 tests of 6.
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/6 subtests 

Test Summary Report
-------------------
normalize_path.t (Wstat: 512 Tests: 6 Failed: 2)
  Failed tests:  5-6
  Non-zero exit status: 2
Files=1, Tests=6,  0 wallclock secs ( 0.03 usr  0.00 sys +  0.02 cusr  0.00 csys =  0.05 CPU)
Result: FAIL

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions