| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 return translations[locale]; | 60 return translations[locale]; |
| 61 | 61 |
| 62 let languagePart = locale.substring(0, locale.indexOf("-")); | 62 let languagePart = locale.substring(0, locale.indexOf("-")); |
| 63 if (languagePart && languagePart in translations) | 63 if (languagePart && languagePart in translations) |
| 64 return translations[languagePart]; | 64 return translations[languagePart]; |
| 65 | 65 |
| 66 let defaultLocale = "en-US"; | 66 let defaultLocale = "en-US"; |
| 67 return translations[defaultLocale]; | 67 return translations[defaultLocale]; |
| 68 } | 68 } |
| 69 | 69 |
| 70 function parseVersionComponent(comp) | |
| 71 { | |
| 72 if (comp == "*") | |
| 73 return Infinity; | |
| 74 return parseInt(comp, 10) || 0; | |
| 75 } | |
| 76 | |
| 70 function compareVersion(v1, v2) | 77 function compareVersion(v1, v2) |
| 71 { | 78 { |
| 72 let regexp = /^(.*?)([a-z].*)?$/i; | 79 let regexp = /^(.*?)([a-z].*)?$/i; |
|
Manish Jethani
2017/09/22 23:28:51
If "57.0a9" vs "57.0a10" matters, we could handle
Sebastian Noack
2017/09/23 00:32:50
This would add notable complexity to this implemen
| |
| 73 let [, head1, tail1] = regexp.exec(v1); | 80 let [, head1, tail1] = regexp.exec(v1); |
| 74 let [, head2, tail2] = regexp.exec(v2); | 81 let [, head2, tail2] = regexp.exec(v2); |
| 75 let components1 = head1.split("."); | 82 let components1 = head1.split("."); |
| 76 let components2 = head2.split("."); | 83 let components2 = head2.split("."); |
| 77 | 84 |
| 78 for (let i = 0; i < components1.length || | 85 for (let i = 0; i < components1.length || |
| 79 i < components2.length; i++) | 86 i < components2.length; i++) |
| 80 { | 87 { |
| 81 let comp1 = components1[i]; | 88 let result = parseVersionComponent(components1[i]) - |
| 82 let comp2 = components2[i]; | 89 parseVersionComponent(components2[i]) || 0; |
| 83 | |
| 84 let result = (comp1 == "*" ? Infinity : parseInt(comp1, 10) || 0) - | |
| 85 (comp2 == "*" ? Infinity : parseInt(comp2, 10) || 0) || 0; | |
|
Wladimir Palant
2017/09/22 10:11:49
The readability of this statement is very suboptim
Sebastian Noack
2017/09/23 00:32:50
I kinda liked the one-liner, but what I like about
| |
| 86 | 90 |
| 87 if (result != 0) | 91 if (result != 0) |
| 88 return result; | 92 return result; |
| 89 } | 93 } |
| 90 | 94 |
| 91 return tail1 == tail2 ? 0 : !tail1 || tail2 && tail1 > tail2 ? 1 : -1; | 95 // Compare version suffix (e.g. 0.1alpha < 0.1b1 < 01.b2 < 0.1). |
|
Wladimir Palant
2017/09/22 10:11:49
This part isn't covered by unit tests (so far thes
Manish Jethani
2017/09/22 23:23:41
FWIW "tail2 && tail1 > tail2" can be just "tail1 >
Sebastian Noack
2017/09/23 00:32:50
Done.
Sebastian Noack
2017/09/23 00:32:50
This is actually true (it wasn't in earlier when I
| |
| 96 // However, note that this is a simple string comparision, meaning: b10 < b2 | |
| 97 if (tail1 == tail2) | |
| 98 return 0; | |
| 99 if (!tail1 || tail2 && tail1 > tail2) | |
| 100 return 1; | |
| 101 return -1; | |
| 92 } | 102 } |
| 93 | 103 |
| 94 /** | 104 /** |
| 95 * The object providing actual downloading functionality. | 105 * The object providing actual downloading functionality. |
| 96 * @type {Downloader} | 106 * @type {Downloader} |
| 97 */ | 107 */ |
| 98 let downloader = null; | 108 let downloader = null; |
| 99 let localData = []; | 109 let localData = []; |
| 100 | 110 |
| 101 /** | 111 /** |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 503 else if (index != -1 && forceValue !== true) | 513 else if (index != -1 && forceValue !== true) |
| 504 categories.splice(index, 1); | 514 categories.splice(index, 1); |
| 505 | 515 |
| 506 // HACK: JSON values aren't saved unless they are assigned a | 516 // HACK: JSON values aren't saved unless they are assigned a |
| 507 // different object. | 517 // different object. |
| 508 Prefs.notifications_ignoredcategories = | 518 Prefs.notifications_ignoredcategories = |
| 509 JSON.parse(JSON.stringify(categories)); | 519 JSON.parse(JSON.stringify(categories)); |
| 510 } | 520 } |
| 511 }; | 521 }; |
| 512 Notification.init(); | 522 Notification.init(); |
| LEFT | RIGHT |