| OLD | NEW |
| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 /** | 69 /** |
| 70 * Will be set to true if no patterns.ini file exists. | 70 * Will be set to true if no patterns.ini file exists. |
| 71 * @type {boolean} | 71 * @type {boolean} |
| 72 */ | 72 */ |
| 73 firstRun: false, | 73 firstRun: false, |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * Map of properties listed in the filter storage file before the sections | 76 * Map of properties listed in the filter storage file before the sections |
| 77 * start. Right now this should be only the format version. | 77 * start. Right now this should be only the format version. |
| 78 * @type {Map.<string,string>} |
| 78 */ | 79 */ |
| 79 fileProperties: Object.create(null), | 80 fileProperties: new Map(), |
| 80 | 81 |
| 81 /** | 82 /** |
| 82 * List of filter subscriptions containing all filters | 83 * List of filter subscriptions containing all filters |
| 83 * @type {Subscription[]} | 84 * @type {Subscription[]} |
| 84 */ | 85 */ |
| 85 subscriptions: [], | 86 subscriptions: [], |
| 86 | 87 |
| 87 /** | 88 /** |
| 88 * Map of subscriptions already on the list, by their URL/identifier | 89 * Map of subscriptions already on the list, by their URL/identifier |
| 89 * @type {Map.<string,Subscription>} | 90 * @type {Map.<string,Subscription>} |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 filter.subscriptions.splice(i, 1); | 683 filter.subscriptions.splice(i, 1); |
| 683 } | 684 } |
| 684 } | 685 } |
| 685 | 686 |
| 686 /** | 687 /** |
| 687 * Listener returned by FilterStorage.importData(), parses filter data. | 688 * Listener returned by FilterStorage.importData(), parses filter data. |
| 688 * @constructor | 689 * @constructor |
| 689 */ | 690 */ |
| 690 function INIParser() | 691 function INIParser() |
| 691 { | 692 { |
| 692 this.fileProperties = this.curObj = {}; | 693 this.fileProperties = this.curObj = new Map(); |
| 693 this.subscriptions = []; | 694 this.subscriptions = []; |
| 694 this.knownFilters = new Map(); | 695 this.knownFilters = new Map(); |
| 695 this.knownSubscriptions = new Map(); | 696 this.knownSubscriptions = new Map(); |
| 696 } | 697 } |
| 697 INIParser.prototype = | 698 INIParser.prototype = |
| 698 { | 699 { |
| 699 linesProcessed: 0, | 700 linesProcessed: 0, |
| 700 subscriptions: null, | 701 subscriptions: null, |
| 701 knownFilters: null, | 702 knownFilters: null, |
| 702 knownSubscriptions: null, | 703 knownSubscriptions: null, |
| 703 wantObj: true, | 704 wantObj: true, |
| 704 fileProperties: null, | 705 fileProperties: null, |
| 705 curObj: null, | 706 curObj: null, |
| 706 curSection: null, | 707 curSection: null, |
| 707 | 708 |
| 708 process(val) | 709 process(val) |
| 709 { | 710 { |
| 710 let origKnownFilters = Filter.knownFilters; | 711 let origKnownFilters = Filter.knownFilters; |
| 711 Filter.knownFilters = this.knownFilters; | 712 Filter.knownFilters = this.knownFilters; |
| 712 let origKnownSubscriptions = Subscription.knownSubscriptions; | 713 let origKnownSubscriptions = Subscription.knownSubscriptions; |
| 713 Subscription.knownSubscriptions = this.knownSubscriptions; | 714 Subscription.knownSubscriptions = this.knownSubscriptions; |
| 714 let match; | 715 let match; |
| 715 try | 716 try |
| 716 { | 717 { |
| 717 if (this.wantObj === true && (match = /^(\w+)=(.*)$/.exec(val))) | 718 if (this.wantObj === true && (match = /^(\w+)=(.*)$/.exec(val))) |
| 718 this.curObj[match[1]] = match[2]; | 719 this.curObj.set(match[1], match[2]); |
| 719 else if (val === null || (match = /^\s*\[(.+)\]\s*$/.exec(val))) | 720 else if (val === null || (match = /^\s*\[(.+)\]\s*$/.exec(val))) |
| 720 { | 721 { |
| 721 if (this.curObj) | 722 if (this.curObj) |
| 722 { | 723 { |
| 723 // Process current object before going to next section | 724 // Process current object before going to next section |
| 724 switch (this.curSection) | 725 switch (this.curSection) |
| 725 { | 726 { |
| 726 case "filter": | 727 case "filter": |
| 727 if ("text" in this.curObj) | 728 if (this.curObj.has("text")) |
| 728 Filter.fromObject(this.curObj); | 729 Filter.fromMap(this.curObj); |
| 729 break; | 730 break; |
| 730 case "subscription": { | 731 case "subscription": { |
| 731 let subscription = Subscription.fromObject(this.curObj); | 732 let subscription = Subscription.fromMap(this.curObj); |
| 732 if (subscription) | 733 if (subscription) |
| 733 this.subscriptions.push(subscription); | 734 this.subscriptions.push(subscription); |
| 734 break; | 735 break; |
| 735 } | 736 } |
| 736 case "subscription filters": | 737 case "subscription filters": |
| 737 if (this.subscriptions.length) | 738 if (this.subscriptions.length) |
| 738 { | 739 { |
| 739 let subscription = this.subscriptions[ | 740 let subscription = this.subscriptions[ |
| 740 this.subscriptions.length - 1 | 741 this.subscriptions.length - 1 |
| 741 ]; | 742 ]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 752 | 753 |
| 753 if (val === null) | 754 if (val === null) |
| 754 return; | 755 return; |
| 755 | 756 |
| 756 this.curSection = match[1].toLowerCase(); | 757 this.curSection = match[1].toLowerCase(); |
| 757 switch (this.curSection) | 758 switch (this.curSection) |
| 758 { | 759 { |
| 759 case "filter": | 760 case "filter": |
| 760 case "subscription": | 761 case "subscription": |
| 761 this.wantObj = true; | 762 this.wantObj = true; |
| 762 this.curObj = {}; | 763 this.curObj = new Map(); |
| 763 break; | 764 break; |
| 764 case "subscription filters": | 765 case "subscription filters": |
| 765 this.wantObj = false; | 766 this.wantObj = false; |
| 766 this.curObj = []; | 767 this.curObj = []; |
| 767 break; | 768 break; |
| 768 default: | 769 default: |
| 769 this.wantObj = undefined; | 770 this.wantObj = undefined; |
| 770 this.curObj = null; | 771 this.curObj = null; |
| 771 } | 772 } |
| 772 } | 773 } |
| 773 else if (this.wantObj === false && val) | 774 else if (this.wantObj === false && val) |
| 774 this.curObj.push(val.replace(/\\\[/g, "[")); | 775 this.curObj.push(val.replace(/\\\[/g, "[")); |
| 775 } | 776 } |
| 776 finally | 777 finally |
| 777 { | 778 { |
| 778 Filter.knownFilters = origKnownFilters; | 779 Filter.knownFilters = origKnownFilters; |
| 779 Subscription.knownSubscriptions = origKnownSubscriptions; | 780 Subscription.knownSubscriptions = origKnownSubscriptions; |
| 780 } | 781 } |
| 781 } | 782 } |
| 782 }; | 783 }; |
| OLD | NEW |