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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 */ | 87 */ |
88 function parseScript(script) | 88 function parseScript(script) |
89 { | 89 { |
90 let tree = []; | 90 let tree = []; |
91 | 91 |
92 let escape = false; | 92 let escape = false; |
93 let withinQuotes = false; | 93 let withinQuotes = false; |
94 | 94 |
95 let unicodeEscape = null; | 95 let unicodeEscape = null; |
96 | 96 |
| 97 let quotesClosed = false; |
| 98 |
97 let call = []; | 99 let call = []; |
98 let argument = ""; | 100 let argument = ""; |
99 | 101 |
100 for (let character of script.trim() + ";") | 102 for (let character of script.trim() + ";") |
101 { | 103 { |
| 104 let afterQuotesClosed = quotesClosed; |
| 105 quotesClosed = false; |
| 106 |
102 if (unicodeEscape != null) | 107 if (unicodeEscape != null) |
103 { | 108 { |
104 unicodeEscape += character; | 109 unicodeEscape += character; |
105 | 110 |
106 if (unicodeEscape.length == 4) | 111 if (unicodeEscape.length == 4) |
107 { | 112 { |
108 let codePoint = parseInt(unicodeEscape, 16); | 113 let codePoint = parseInt(unicodeEscape, 16); |
109 if (!isNaN(codePoint)) | 114 if (!isNaN(codePoint)) |
110 argument += String.fromCodePoint(codePoint); | 115 argument += String.fromCodePoint(codePoint); |
111 | 116 |
112 unicodeEscape = null; | 117 unicodeEscape = null; |
113 } | 118 } |
114 } | 119 } |
115 else if (escape) | 120 else if (escape) |
116 { | 121 { |
117 escape = false; | 122 escape = false; |
118 | 123 |
119 if (character == "u") | 124 if (character == "u") |
120 unicodeEscape = ""; | 125 unicodeEscape = ""; |
121 else | 126 else |
122 argument += singleCharacterEscapes.get(character) || character; | 127 argument += singleCharacterEscapes.get(character) || character; |
123 } | 128 } |
124 else if (character == "\\") | 129 else if (character == "\\") |
125 { | 130 { |
126 escape = true; | 131 escape = true; |
127 } | 132 } |
128 else if (character == "'") | 133 else if (character == "'") |
129 { | 134 { |
130 withinQuotes = !withinQuotes; | 135 withinQuotes = !withinQuotes; |
| 136 |
| 137 if (!withinQuotes) |
| 138 quotesClosed = true; |
131 } | 139 } |
132 else if (withinQuotes || character != ";" && !/\s/.test(character)) | 140 else if (withinQuotes || character != ";" && !/\s/.test(character)) |
133 { | 141 { |
134 argument += character; | 142 argument += character; |
135 } | 143 } |
136 else | 144 else |
137 { | 145 { |
138 if (argument) | 146 if (argument || afterQuotesClosed) |
139 { | 147 { |
140 call.push(argument); | 148 call.push(argument); |
141 argument = ""; | 149 argument = ""; |
142 } | 150 } |
143 | 151 |
144 if (character == ";" && call.length > 0) | 152 if (character == ";" && call.length > 0) |
145 { | 153 { |
146 tree.push(call); | 154 tree.push(call); |
147 call = []; | 155 call = []; |
148 } | 156 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 let value = imports[name]; | 188 let value = imports[name]; |
181 if (typeof value == "function") | 189 if (typeof value == "function") |
182 value(...args); | 190 value(...args); |
183 } | 191 } |
184 } | 192 } |
185 } | 193 } |
186 `; | 194 `; |
187 } | 195 } |
188 | 196 |
189 exports.compileScript = compileScript; | 197 exports.compileScript = compileScript; |
OLD | NEW |