|
5 | 5 | // Makes a copy of each file at filename.bak. |
6 | 6 | // |
7 | 7 | // Usage: |
8 | | -// (install node and npm) |
9 | 8 | // cd https-everywhere |
10 | | -// ./makecrx.sh |
| 9 | +// ./makecrx.sh # to build default.rulesets |
11 | 10 | // cd rewriter |
12 | | -// js rewriter.js ~/path/to/my/webapp |
| 11 | +// (install node and npm) |
| 12 | +// npm install |
| 13 | +// node rewriter.js ~/path/to/my/webapp |
| 14 | +// cd ~/path/to/my/webapp |
| 15 | +// git diff |
13 | 16 |
|
14 | 17 | var path = require("path"), |
15 | 18 | fs = require("fs"), |
@@ -46,6 +49,15 @@ function processDir(dir) { |
46 | 49 | })); |
47 | 50 | } |
48 | 51 |
|
| 52 | +// Overwrite the default URI find_uri_expression with a modified one that |
| 53 | +// mitigates a catastrophic backtracking issue common in CSS. |
| 54 | +// The workaround was to insist that URLs start with http, since those are the |
| 55 | +// only ones we want to rewrite anyhow. Note that this may still go exponential |
| 56 | +// on certain inputs. http://www.regular-expressions.info/catastrophic.html |
| 57 | +// Example string that blows up URI.withinString: |
| 58 | +// image:url(http://img.youtube.com/vi/x7f |
| 59 | +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; |
| 60 | + |
49 | 61 | function processFile(filename) { |
50 | 62 | var contents = fs.readFileSync(filename, {encoding: 'utf-8'}); |
51 | 63 | var rewrittenFile = URI.withinString(contents, function(url) { |
@@ -74,6 +86,7 @@ function processFile(filename) { |
74 | 86 | } |
75 | 87 |
|
76 | 88 | function loadRuleSets() { |
| 89 | + console.log("Loading rules..."); |
77 | 90 | var fileContents = fs.readFileSync(path.join(__dirname, '../pkg/crx/rules/default.rulesets'), {encoding: 'utf-8'}); |
78 | 91 | var xml = new DOMParser().parseFromString(fileContents, 'text/xml'); |
79 | 92 | ruleSets = new rules.RuleSets("fake user agent", lrucache.LRUCache, xml, {}); |
|
0 commit comments