KES777 / mojo

Mojolicious - Perl real-time web framework
http://mojolicio.us
Artistic License 2.0
0 stars 0 forks source link

Mojolicious do not ignore multiple path separator #23

Open KES777 opened 6 years ago

KES777 commented 6 years ago

08:08 kes Hi. Is there a way to distinguish global stash values from passed arguments to template? 08:08 berov joined #mojo 08:08 kes I have next problem: http://paste.scsys.co.uk/575194 2 more elements. Show/hide. 08:25 kes https://metacpan.org/source/SRI/Mojolicious-7.70/lib/Mojolicious/Renderer.pm#L86 08:25 hm... or just ->render_to_string( 'template', args => { name => $name, %attrs } ) 2 more elements. Show/hide. 08:49 kes seems bug. When I refer to template as ->render( "control//form_field" ) I get error: 08:49 Template "control//form_field.html.ep" not found 08:50 But when this template is extracted from DATA section and placed on filesystem. There is no such error 08:51 because both files: control//form_field.html.ep and control/form_field.html.ep, - in unix refer to same file 08:55 sequence '//' in path should be replaced by '/' here: https://metacpan.org/source/SRI/Mojolicious-7.70/lib/Mojolicious/Renderer.pm#L166

--- a/lib/Mojolicious/Renderer.pm
+++ b/lib/Mojolicious/Renderer.pm
@@ -164,6 +164,7 @@ sub template_name {
       if @$handlers && !defined $handler || grep { $_ eq $handler } @$handlers;
   }

+  $template =~ s#/(?=/)##g;
   return defined $handler ? "$template.$handler" : $template;
 }

09:05 This is required because 'control//form_field.html.ep' and 'control/form_field.html.ep' are different keys and do not point to same template here: 09:05 https://metacpan.org/source/SRI/Mojolicious-7.70/lib/Mojolicious/Renderer.pm#L52

returning to the issue when template is not found when placed into __DATA__ section What do you think about this patch? https://irclog.perlgeek.de/mojo/2018-03-02#i_15875667 I have found the spec which says: Multiple successive slashes are considered to be the same as one slash. https://unix.stackexchange.com/a/1919/129967 kes: Is that true on non-unix platforms? nic: multiple /s are converted to single /s http://www.mit.edu/afs.new/athena/system/i386_deb50/os-ubuntu-9.04/usr/share/plt/doc/reference/windowspaths.html Most operating systems allow the inclusion of multiple slashes between file name or directory components of a file path. This is true of both Windows and most *nix operating systems prof: https://knowledgebase.progress.com/articles/Article/Why-is-a-double-slash-valid-in-a-file-path macos is posix system. POSIX define next: systems must treat multiple slashes as single slashes https://en.wikipedia.org/wiki/Path_(computing)#POSIX_pathname_definition nic: So, Yes, it is true on non-unix platforms here is example how path with multiple directory separators interpreted by windows: https://stackoverflow.com/a/33028881/4632019 with prof link to MSDN In any case (Because template name is expanded to filename) Before using $template as KEY at https://metacpan.org/source/SRI/Mojolicious-7.70/lib/Mojolicious/Renderer.pm#L52 we should do same transformation as &template_path does: https://metacpan.org/source/SRI/Mojolicious-7.70/lib/Mojolicious/Renderer.pm#L172 in this case the behavior of treating multiple path separator is relied on File::Spec::catfile. Which will do job right Personally I prefer regex solution to ignore multiple path separators and one more link: https://stackoverflow.com/a/10161264/4632019 >HTTP RFC 2396 defines path separator to be single slash