[Rt-commit] r5345 - in CSS-Squish: lib/CSS t t/css

trs at bestpractical.com trs at bestpractical.com
Wed Jun 7 16:39:21 EDT 2006


Author: trs
Date: Wed Jun  7 16:39:20 2006
New Revision: 5345

Added:
   CSS-Squish/t/05-basic-loop-prevention.t
   CSS-Squish/t/css/05-loop-prevention-2.css
   CSS-Squish/t/css/05-loop-prevention-3.css
   CSS-Squish/t/css/05-loop-prevention.css
Modified:
   CSS-Squish/   (props changed)
   CSS-Squish/lib/CSS/Squish.pm

Log:
 r12756 at zot:  tom | 2006-06-07 16:38:52 -0400
 Some basic loop checking and adding a note in the docs


Modified: CSS-Squish/lib/CSS/Squish.pm
==============================================================================
--- CSS-Squish/lib/CSS/Squish.pm	(original)
+++ CSS-Squish/lib/CSS/Squish.pm	Wed Jun  7 16:39:20 2006
@@ -116,6 +116,12 @@
                 my @spec = File::Spec->splitpath( $file );
                 my $import_path = File::Spec->catpath( @spec[0,1], $import );
 
+                if ($import_path eq $file) {
+                    # We're in a direct loop, don't import this
+                    print $dest "/** Skipping: \n", $line, "  */\n\n";
+                    next IMPORT;
+                }
+
                 print $dest "\n/**\n  * From $file: $line  */\n\n";
                 
                 if (defined $media) {
@@ -146,6 +152,9 @@
 to not be parsed.  Make sure the @import rules are the very first thing in
 the file (and only one per line).
 
+Only direct @import loops (i.e. where a file imports itself) are checked
+and skipped.  It's easy enough to get this module in a loop.  Don't do it.
+
 All other bugs should be reported via
 L<http://rt.cpan.org/Public/Dist/Display.html?Name=CSS-Squish>
 or L<bugs-CSS-Squish at rt.cpan.org>.

Added: CSS-Squish/t/05-basic-loop-prevention.t
==============================================================================
--- (empty file)
+++ CSS-Squish/t/05-basic-loop-prevention.t	Wed Jun  7 16:39:20 2006
@@ -0,0 +1,24 @@
+#!/usr/bin/perl -w
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+use Test::LongString;
+
+use_ok("CSS::Squish");
+
+my $expected = <<'EOT';
+
+/** Skipping: 
+ at import "05-loop-prevention.css";
+  */
+
+foobar
+EOT
+
+my $result = CSS::Squish->concatenate('t/css/05-loop-prevention.css');
+
+is_string($result, $expected, "Skip direct loop-causing imports");
+
+
+

Added: CSS-Squish/t/css/05-loop-prevention-2.css
==============================================================================
--- (empty file)
+++ CSS-Squish/t/css/05-loop-prevention-2.css	Wed Jun  7 16:39:20 2006
@@ -0,0 +1,2 @@
+ at import "05-loop-prevention-3.css";
+main

Added: CSS-Squish/t/css/05-loop-prevention-3.css
==============================================================================
--- (empty file)
+++ CSS-Squish/t/css/05-loop-prevention-3.css	Wed Jun  7 16:39:20 2006
@@ -0,0 +1,2 @@
+ at import "05-loop-prevention-2.css";
+import 2

Added: CSS-Squish/t/css/05-loop-prevention.css
==============================================================================
--- (empty file)
+++ CSS-Squish/t/css/05-loop-prevention.css	Wed Jun  7 16:39:20 2006
@@ -0,0 +1,3 @@
+
+ at import "05-loop-prevention.css";
+foobar


More information about the Rt-commit mailing list