[Pkg-mozext-commits] [SCM] perspectives-extension branch, debian, updated. 4.2-4-136-gd6962eb

Dave Schaefer dave.schaefer at gmail.com
Thu Jun 28 22:04:44 UTC 2012


The following commit has been merged in the debian branch:
commit f7aefdcaacc7db7e80b59b44aa3820233e02d4a0
Author: Dave Schaefer <dave.schaefer at gmail.com>
Date:   Thu Jun 7 22:37:33 2012 -0700

    Build system, Unit tests - Add a perl script to validate .dtd entities when building.
    
    Currently we check for invalid entity characters.
    Removing bad characters during the build is preferable to simply detecting them during the unit tests, as some people may not run the unit tests.
    Running the script as part of the build prevents us from posting a broken build, where users might have their plugin crash and not know how to fix it.
    Plus you never have to remember to do it - it always runs.
    
    Also, add a list of requirements in the README. This commit makes perl a new requirement.

diff --git a/Makefile b/Makefile
index 797c307..472dbfd 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,8 @@
 all:
+	# remove invalid entity characters as part of the build
+	# 1. we never have to remember to run this step manually
+	# 2. this ensures the plugin won't crash
+	find ./plugin/chrome/locale/ -name "*.dtd" | xargs perl -w checkdtds.pl
 	rm -rf build/
 	mkdir build
 	cp -r plugin/* build/
diff --git a/README b/README
index 3866c9f..6bbafbf 100644
--- a/README
+++ b/README
@@ -5,6 +5,13 @@ For more information on Perspectives, see: http://www.perspectives-project.org
 
 HACKING
 
+Requirements:
+- make
+- zip
+- perl (to run the dtd sanity script)
+- a POSIX command line environment
+
+
 To build, just type "make" (assuming of course you have make installed!). This will create a file called 'Perspectives.xpi'.  
 
 You can run this in Firefox using File -> Open and browsing to the Perspectives.xpi file.  
diff --git a/checkdtds.pl b/checkdtds.pl
new file mode 100644
index 0000000..a58c6d2
--- /dev/null
+++ b/checkdtds.pl
@@ -0,0 +1,145 @@
+#
+#   This file is part of the Perspectives build system
+#
+#   Copyright (C) 2011 Dan Wendlandt
+#
+#   This program is free software: you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation, version 3 of the License.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+use strict;
+use warnings;
+
+#Entities loaded by .xhtml files cannot contain the characters
+#"%<>
+#, or the page will fail to load.
+#So replace any such chars with their web-safe counterparts.
+#Input: .dtd entities files that will be loaded into any .xhtml page.
+#Output: files with sanitized entities, with a list of issues and replacements on stdout
+#
+#Note: .dtd files that aren't loaded into .xhtml don't need to be scanned.
+
+
+my (@files) = @ARGV;
+
+my $errstatus = 0;
+
+print "Checking DTDs for invalid characters and entities...\n";
+
+for my $file (@files) {
+
+	my $fileerrstatus = 0;
+
+	if (! -e $file) {
+		print "ERROR: file '$file' doesn't exist. Skipping.\n";
+		$errstatus = 1;
+		$fileerrstatus = 1;
+		next;
+	}
+	elsif(! -f $file) {
+		print "ERROR: '$file' is not a file. Skipping.\n";
+		$errstatus = 1;
+		$fileerrstatus = 1;
+		next;
+	}
+
+	print "  $file...\n";
+
+	#VERY IMPORTANT: read and write files using utf-8 encoding,
+	#or we'll delete all of the unicode characters and mess up localization
+	my $op = open(FILE, "<:encoding(utf-8)", "$file");
+	if (!$op) {
+		print "Cannot open '$file' for reading: $!\n";
+		next;
+	}
+
+	#since entities could span multiple lines, read the whole file first and then split
+	my $data;
+
+	while (<FILE>) {
+		$data .= $_;
+	}
+
+	close FILE;
+
+	if (!$data) {
+		print "No data in $file - is something wrong?\n";
+		$errstatus = 1;
+		$fileerrstatus = 1;
+		next;
+	}
+
+	#don't write to the file in-place;
+	#write to a copy and then rename the output file only if nothing went wrong.
+
+	my $outfile = "$file.sane";
+
+	$op = open(FILE, ">:encoding(utf-8)", "$outfile");
+	if (!$op) {
+		print "Cannot open '$outfile' for writing: $!\n";
+		next;
+	}
+
+	my $delim = "<!";
+	my $delimrx = quotemeta $delim;
+
+	my @parts = split(/$delimrx/, $data);
+	$data = "";
+
+	for my $part (@parts){
+		#entities look like
+		#<!ENTITY keyName "Some text goes here!">
+		if ($part =~ /(ENTITY +[A-Za-z0-9]+ +")([^"]*)(" *>[^<]*)/) {
+			#save matches otherwise we lose them
+			my $first = $1;
+			my $ent = $2;
+			my $last = $3;
+
+			if ($ent =~ /[%<>]/) {
+				$ent =~ s/%/%/g;
+				$ent =~ s/</</g;
+				$ent =~ s/>/>/g;
+				my $newline = $first . $ent . $last . "\n";
+				print "  Replacing '$part' with '$newline'\n";
+				$part = $newline;
+			}
+
+			print FILE $delim . $part;
+		}
+
+		#comments look like:
+		#<!-- any text here -->
+		elsif ($part =~ /(--[^>]+-->[^<]*)/) {
+			print FILE $delim . $part;
+		}
+
+		elsif ($part !~ /^\s*$/) { #blank line
+				$fileerrstatus = 1;
+				print "  Malformed entry '$part'; please run the tests and fix.\n";
+		}
+	}
+
+	close FILE;
+
+	print "  "; #spacing to make the output look pretty
+
+	if ($fileerrstatus == 0) {
+		print "Success. ";
+		rename $outfile, $file;
+	}
+
+	unlink $outfile;
+
+	print "Done\n";
+}
+
+exit $errstatus;

-- 
perspectives-extension



More information about the Pkg-mozext-commits mailing list