Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/rules.js

Issue 8382011: Applied changes from emailed code review (Closed)
Patch Set: Applied remaining changes Created Sept. 26, 2012, 9:02 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* This Source Code Form is subject to the terms of the Mozilla Public 1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
4 4
5 Cu.import("resource://gre/modules/Services.jsm"); 5 Cu.import("resource://gre/modules/Services.jsm");
6 Cu.import("resource://gre/modules/FileUtils.jsm"); 6 Cu.import("resource://gre/modules/FileUtils.jsm");
7 7
8 let {Prefs} = require("prefs"); 8 let {Prefs} = require("prefs");
9 9
10 let RULES_VERSION = 2; 10 let RULES_VERSION = 2;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 let customRules = Prefs.custom_replace; 143 let customRules = Prefs.custom_replace;
144 for (let searchString in customRules) 144 for (let searchString in customRules)
145 { 145 {
146 let replacement = customRules[searchString]; 146 let replacement = customRules[searchString];
147 searchString = searchString.toLowerCase(); 147 searchString = searchString.toLowerCase();
148 if (/^re:+/.test(searchString)) 148 if (/^re:+/.test(searchString))
149 domain = domain.replace(new RegExp(RegExp.rightContext, "g"), replacement) ; 149 domain = domain.replace(new RegExp(RegExp.rightContext, "g"), replacement) ;
150 else 150 else
151 domain = domain.replace(searchString, replacement); 151 domain = domain.replace(searchString, replacement);
152 } 152 }
153
154 // Apply user's whitelist
155 let whitelist = Prefs.whitelist;
156 if (whitelist.hasOwnProperty(domain) || /^www\./.test(domain) && whitelist.has OwnProperty(domain.substr(4)))
157 {
158 return domain;
159 }
153 160
154 // Now apply our rules on the domain name 161 // Now apply our rules on the domain name
155 for (let i = 0, l = rules.expressions.length; i < l; i++) 162 for (let i = 0, l = rules.expressions.length; i < l; i++)
156 domain = applyExpression(domain, rules.expressions[i]); 163 domain = applyExpression(domain, rules.expressions[i]);
157 164
158 // Find similar known domains, test domains without the www. prefix 165 // Find similar known domains, test domains without the www. prefix
159 if (domain.substr(0, 4) == "www.") 166 if (domain.substr(0, 4) == "www.")
160 domain = "www." + getBestMatch(domain.substr(4), rules.domain, 1, "."); 167 domain = "www." + getBestMatch(domain.substr(4), rules.domain, 1, ".");
161 else 168 else
162 domain = getBestMatch(domain, rules.domain, 1, "."); 169 domain = getBestMatch(domain, rules.domain, 1, ".");
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 bestSuggestionDistance = distance; 312 bestSuggestionDistance = distance;
306 bestSuggestionMatched = matchedLen; 313 bestSuggestionMatched = matchedLen;
307 bestSuggestionPriority = priority; 314 bestSuggestionPriority = priority;
308 } 315 }
309 } 316 }
310 if (bestSuggestion) 317 if (bestSuggestion)
311 return input.substr(0, input.length - bestSuggestionMatched) + bestSuggestio n; 318 return input.substr(0, input.length - bestSuggestionMatched) + bestSuggestio n;
312 else 319 else
313 return input; 320 return input;
314 } 321 }
OLDNEW

Powered by Google App Engine
This is Rietveld