mojo icon indicating copy to clipboard operation
mojo copied to clipboard

psgi env: fix double encoding of path parts

Open sparrow2009 opened this issue 7 months ago • 1 comments

Fix double encoding of path parts when parsing a PSGI env with a SCRIPT_NAME set.

sparrow2009 avatar Mar 28 '25 14:03 sparrow2009

A final note: This is actually a downstream patch in order to handle a race condition that is built into Mojo::Path::to_string().

my $path = ...;
Mojo::Path->new( $path )->to_string() # expects a decoded and unescaped $path as it encodes and escapes $path
my $path_obj = Mojo::Path->new( $path );
$path_obj->parts; # expects an encoded and escaped $path as it unescapes and decodes $path
$path_obj->to_string(); # encodes and escapes path parts

Thus if one happens to call to_string() on an object passed an encoded string on construction and did not call a method that _parse()d the string before double encoding occurs.

From reading the object construction examples listed in the synopsis of Mojo::Path I get the impression (correct me if I am wrong) that passing both encoded and decoded strings on object construction is valid and actually considered a feature. This design inevitably makes it impossible however to tell apart the nature of the construction string (encoded/decoded) later (and if my reasoning is correct can be considered a design flaw).

sparrow2009 avatar Apr 07 '25 09:04 sparrow2009