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

Side by Side Diff: chrome/content/ui/subscriptionSelection.js

Issue 5325266087837696: Issue 1675 - Use String.trim() to strip leading and trailing whitespaces (Firefox) (Closed)
Patch Set: Created Dec. 8, 2014, 5:24 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/content/ui/filters-subscriptionactions.js ('k') | lib/filterClasses.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 { 232 {
233 messageElement.setAttribute("invisible", "true"); 233 messageElement.setAttribute("invisible", "true");
234 addMainCheckbox.setAttribute("invisible", "true"); 234 addMainCheckbox.setAttribute("invisible", "true");
235 } 235 }
236 } 236 }
237 237
238 function validateURL(url) 238 function validateURL(url)
239 { 239 {
240 if (!url) 240 if (!url)
241 return null; 241 return null;
242 url = url.replace(/^\s+/, "").replace(/\s+$/, ""); 242 url = url.trim();
243 243
244 // Is this a file path? 244 // Is this a file path?
245 try { 245 try {
246 let file = new FileUtils.File(url); 246 let file = new FileUtils.File(url);
247 return Services.io.newFileURI(file).spec; 247 return Services.io.newFileURI(file).spec;
248 } catch (e) {} 248 } catch (e) {}
249 249
250 // Is this a valid URL? 250 // Is this a valid URL?
251 let uri = Utils.makeURI(url); 251 let uri = Utils.makeURI(url);
252 if (uri) 252 if (uri)
253 return uri.spec; 253 return uri.spec;
254 254
255 return null; 255 return null;
256 } 256 }
257 257
258 function addSubscription() 258 function addSubscription()
259 { 259 {
260 let url = E("location").value; 260 let url = E("location").value;
261 url = validateURL(url); 261 url = validateURL(url);
262 if (!url) 262 if (!url)
263 { 263 {
264 Utils.alert(window, Utils.getString("subscription_invalid_location")); 264 Utils.alert(window, Utils.getString("subscription_invalid_location"));
265 E("location").focus(); 265 E("location").focus();
266 return false; 266 return false;
267 } 267 }
268 268
269 let title = E("title").value.replace(/^\s+/, "").replace(/\s+$/, ""); 269 let title = E("title").value.trim();
270 if (!title) 270 if (!title)
271 title = url; 271 title = url;
272 272
273 doAddSubscription(url, title); 273 doAddSubscription(url, title);
274 274
275 let addMainCheckbox = E("addMainSubscription") 275 let addMainCheckbox = E("addMainSubscription")
276 if (addMainCheckbox.getAttribute("invisible") != "true" && addMainCheckbox.che cked) 276 if (addMainCheckbox.getAttribute("invisible") != "true" && addMainCheckbox.che cked)
277 { 277 {
278 let mainSubscriptionTitle = addMainCheckbox.getAttribute("_mainSubscriptionT itle"); 278 let mainSubscriptionTitle = addMainCheckbox.getAttribute("_mainSubscriptionT itle");
279 let mainSubscriptionURL = validateURL(addMainCheckbox.value); 279 let mainSubscriptionURL = validateURL(addMainCheckbox.value);
(...skipping 19 matching lines...) Expand all
299 subscription.title = title; 299 subscription.title = title;
300 300
301 if (subscription instanceof DownloadableSubscription && !subscription.lastDown load) 301 if (subscription instanceof DownloadableSubscription && !subscription.lastDown load)
302 Synchronizer.execute(subscription); 302 Synchronizer.execute(subscription);
303 } 303 }
304 304
305 function hasSubscription(url) 305 function hasSubscription(url)
306 { 306 {
307 return FilterStorage.subscriptions.some(function(subscription) subscription in stanceof DownloadableSubscription && subscription.url == url); 307 return FilterStorage.subscriptions.some(function(subscription) subscription in stanceof DownloadableSubscription && subscription.url == url);
308 } 308 }
OLDNEW
« no previous file with comments | « chrome/content/ui/filters-subscriptionactions.js ('k') | lib/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld