Author: tim.bunce
Date: Tue Mar  3 13:35:41 2009
New Revision: 688

Modified:
    trunk/lib/Devel/NYTProf/Util.pm
    trunk/t/30.util.t

Log:
Make html_safe_filename remove colons (and some other chars) from filenames
to avoid problem on windows. E.g.,  
https://rt.cpan.org/Ticket/Display.html?id=43798


Modified: trunk/lib/Devel/NYTProf/Util.pm
==============================================================================
--- trunk/lib/Devel/NYTProf/Util.pm     (original)
+++ trunk/lib/Devel/NYTProf/Util.pm     Tue Mar  3 13:35:41 2009
@@ -216,8 +216,12 @@

  sub html_safe_filename {
      my ($fname) = @_;
-    $fname =~ s{ ^[/\\] }{}x;                      # remove leading / or \
-    $fname =~ s{  [/\\] }{-}xg;                    # replace / and \ with  
html safe -
+    # replace / and \ with html safe '-', we also do a bunch of other
+    # chars, especially ':' for Windows, to make the namer simpler and  
safer
+    $fname =~ s{  [-/\\:\*\?"'<>|]+ }{-}xg;
+    # remove any leading or trailing '-' chars
+    $fname =~ s{^-}{};
+    $fname =~ s{-$}{};
      return $fname;
  }


Modified: trunk/t/30.util.t
==============================================================================
--- trunk/t/30.util.t   (original)
+++ trunk/t/30.util.t   Tue Mar  3 13:35:41 2009
@@ -1,6 +1,9 @@
-use Test::More tests => 20;
+use Test::More tests => 25;

-use Devel::NYTProf::Util qw(fmt_time fmt_incl_excl_time);
+use Devel::NYTProf::Util qw(
+    fmt_time fmt_incl_excl_time
+    html_safe_filename
+);

  my $us = "&micro;s";

@@ -27,3 +30,9 @@
  is(fmt_incl_excl_time(0.1, 0.0997), "100ms (99.7+300$us)");
  is(fmt_incl_excl_time(1.1e-5, 3.5e-6), "11$us (4+8)");

+is html_safe_filename('/foo/bar'), 'foo-bar';
+is html_safe_filename('\foo\bar'), 'foo-bar';
+is html_safe_filename('\foo/bar'), 'foo-bar';
+is html_safe_filename('C:foo'), 'C-foo';
+is html_safe_filename('C:\foo'), 'C-foo';
+is html_safe_filename('<lots>of| 
\'really\'special*"chars"?'), 'lots-of-really-special-chars';

--~--~---------~--~----~------------~-------~--~----~
You've received this message because you are subscribed to
the Devel::NYTProf Development User group.

Group hosted at:  http://groups.google.com/group/develnytprof-dev
Project hosted at:  http://perl-devel-nytprof.googlecode.com
CPAN distribution:  http://search.cpan.org/dist/Devel-NYTProf

To post, email:  [email protected]
To unsubscribe, email:  [email protected]
-~----------~----~----~----~------~----~------~--~---

Reply via email to