diff -Naur Puppet-Tidy-0.1/lib/Puppet/Tidy.pm Puppet-Tidy-0.1-new/lib/Puppet/Tidy.pm
--- Puppet-Tidy-0.1/lib/Puppet/Tidy.pm 2012-12-10 11:49:01.000000000 +0100
+++ Puppet-Tidy-0.1-new/lib/Puppet/Tidy.pm 2013-01-31 15:45:43.000000000 +0100
@@ -190,7 +190,7 @@
next if $line =~ s/(\$\w+)/"$1"/g;
}
$line =~ s/"(.*?)":/\x27$1\x27:/g; # Double to single quoted
- $line =~ s/(\w+):/\x27$1\x27:/g; # Bare word to single quoted
+ $line =~ s/(?!['"])(\w+):(?!.+['"]+)/\x27$1\x27:/g; # Bare word to single quoted
}
}
@@ -252,7 +252,7 @@
foreach my $line (@$input)
{
- $line =~ s,//,#,; # C++ style
+ $line =~ s,(?!['"].+)//(?!.+['"]),#,; # C++ style
$line =~ s,/\*(.*?)(\s+)\*/,#$1,; # C style
}
}
diff -Naur Puppet-Tidy-0.1/t/bug_83072.t Puppet-Tidy-0.1-new/t/bug_83072.t
--- Puppet-Tidy-0.1/t/bug_83072.t 1970-01-01 01:00:00.000000000 +0100
+++ Puppet-Tidy-0.1-new/t/bug_83072.t 2013-01-31 15:46:16.000000000 +0100
@@ -0,0 +1,27 @@
+use strict;
+use Puppet::Tidy;
+use Test::More tests => 2;
+
+# don't assume //.+ is a comment inside strings
+my @output;
+my $source = << 'EOF';
+ source => 'puppet:///foo/bar';
+EOF
+
+my @should_be_output = << 'EOF';
+ source => 'puppet:///foo/bar';
+EOF
+
+Puppet::Tidy::puppettidy(source => $source, destination => \@output);
+is_deeply(@output, @should_be_output, "not messing within strings");
+
+$source = << 'EOF';
+ source => 'puppet:///foo/bar'; // replace me, please
+EOF
+
+@should_be_output = << 'EOF';
+ source => 'puppet:///foo/bar'; # replace me, please
+EOF
+
+Puppet::Tidy::puppettidy(source => $source, destination => \@output);
+is_deeply(@output, @should_be_output, "messing outside strings");