Skip to content

Commit f3a7c77

Browse files
committed
Fixes from review feedback.
1 parent 86f6290 commit f3a7c77

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

chromium/background.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* Fetch and parse XML to be loaded as RuleSets.
3+
*/
14
function getRuleXml(url) {
25
var xhr = new XMLHttpRequest();
36
// Use blocking XHR to ensure everything is loaded by the time

chromium/rules.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,5 +326,6 @@ RuleSets.prototype = {
326326
};
327327

328328
// Export for HTTPS Rewriter if applicable.
329-
if (typeof exports != 'undefined')
329+
if (typeof exports != 'undefined') {
330330
exports.RuleSets = RuleSets;
331+
}

rewriter/rewriter.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ var path = require("path"),
2727

2828
var ruleSets = null;
2929

30+
/**
31+
* For a given directory, recursively edit all files in it that match a filename
32+
* pattern representing source code. Replace URLs in those files with rewritten
33+
* ones if possible.
34+
*/
3035
function processDir(dir) {
3136
var stream = readdirp({
3237
root: dir,
@@ -39,7 +44,7 @@ function processDir(dir) {
3944
stream
4045
.on('warn', function (err) {
4146
console.error('non-fatal error', err);
42-
// optionally call stream.destroy() here in order to abort and cause 'close' to be emitted
47+
// Optionally call stream.destroy() here in order to abort and cause 'close' to be emitted
4348
})
4449
.on('error', function (err) { console.error('fatal error', err); })
4550
.pipe(es.mapSync(function (entry) {
@@ -53,13 +58,15 @@ function processDir(dir) {
5358
}));
5459
}
5560

56-
// Overwrite the default URI find_uri_expression with a modified one that
57-
// mitigates a catastrophic backtracking issue common in CSS.
58-
// The workaround was to insist that URLs start with http, since those are the
59-
// only ones we want to rewrite anyhow. Note that this may still go exponential
60-
// on certain inputs. http://www.regular-expressions.info/catastrophic.html
61-
// Example string that blows up URI.withinString:
62-
// image:url(http://img.youtube.com/vi/x7f
61+
/**
62+
* Overwrite the default URI find_uri_expression with a modified one that
63+
* mitigates a catastrophic backtracking issue common in CSS.
64+
* The workaround was to insist that URLs start with http, since those are the
65+
* only ones we want to rewrite anyhow. Note that this may still go exponential
66+
* on certain inputs. http://www.regular-expressions.info/catastrophic.html
67+
* Example string that blows up URI.withinString:
68+
* image:url(http://img.youtube.com/vi/x7f
69+
*/
6370
URI.find_uri_expression = /\b((?:http:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+)+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»]))/ig;
6471

6572
function processFile(filename) {
@@ -89,6 +96,9 @@ function processFile(filename) {
8996
fs.renameSync(filename + ".new", filename);
9097
}
9198

99+
/**
100+
* Load all rulesets for rewriting.
101+
*/
92102
function loadRuleSets() {
93103
console.log("Loading rules...");
94104
var fileContents = fs.readFileSync(path.join(__dirname, '../pkg/crx/rules/default.rulesets'), 'utf8');
@@ -108,8 +118,9 @@ if (process.argv.length <= 2) {
108118

109119
for (var i = 2; i < process.argv.length; i++) {
110120
var rewritePath = process.argv[i];
111-
if (rewritePath.indexOf('-') == 0)
121+
if (rewritePath.indexOf('-') == 0) {
112122
usage();
123+
}
113124
if (!fs.existsSync(rewritePath)) {
114125
console.log("Path doesn't exist: " + rewritePath);
115126
process.exit(1);

0 commit comments

Comments
 (0)