| Left: | ||
| Right: |
| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 | 129 |
| 130 Snippets.clear(); | 130 Snippets.clear(); |
| 131 compareRules( | 131 compareRules( |
| 132 "Return no filters after clearing", | 132 "Return no filters after clearing", |
| 133 "www.example.com", | 133 "www.example.com", |
| 134 [] | 134 [] |
| 135 ); | 135 ); |
| 136 | 136 |
| 137 test.done(); | 137 test.done(); |
| 138 }; | 138 }; |
| 139 | |
| 140 exports.testScriptParsing = function(test) | |
| 141 { | |
| 142 function checkParsedScript(description, script, expectedTree) | |
| 143 { | |
| 144 let tree = Snippets.parseScript(script); | |
| 145 test.deepEqual(tree, expectedTree, description); | |
| 146 } | |
| 147 | |
| 148 checkParsedScript("Script with no arguments", "foo", [["foo"]]); | |
| 149 checkParsedScript("Script with one argument", "foo 1", [["foo", "1"]]); | |
| 150 checkParsedScript("Script with two arguments", "foo 1 Hello", | |
| 151 [["foo", "1", "Hello"]]); | |
| 152 checkParsedScript("Script with argument containing an escaped space", | |
|
Manish Jethani
2018/04/26 13:27:34
Also note that a single backslash in fact has to b
| |
| 153 "foo Hello\\ world", | |
| 154 [["foo", "Hello world"]]); | |
| 155 checkParsedScript("Script with argument containing a quoted space", | |
| 156 "foo 'Hello world'", | |
| 157 [["foo", "Hello world"]]); | |
| 158 checkParsedScript("Script with argument containing a quoted escaped quote", | |
| 159 "foo 'Hello \\'world\\''", | |
| 160 [["foo", "Hello 'world'"]]); | |
| 161 checkParsedScript("Script with argument containing an escaped semicolon", | |
| 162 "foo TL\\;DR", | |
| 163 [["foo", "TL;DR"]]); | |
| 164 checkParsedScript("Script with argument containing a quoted semicolon", | |
| 165 "foo 'TL;DR'", | |
| 166 [["foo", "TL;DR"]]); | |
| 167 checkParsedScript("Script with multiple commands", "foo; bar", | |
| 168 [["foo"], ["bar"]]); | |
| 169 checkParsedScript("Script with multiple commands and multiple arguments each", | |
| 170 "foo 1 Hello; bar world! #", | |
| 171 [["foo", "1", "Hello"], ["bar", "world!", "#"]]); | |
| 172 checkParsedScript( | |
|
Manish Jethani
2018/04/26 13:25:17
ESLint would not let me format this like the other
| |
| 173 "Script with multiple commands and multiple " + | |
| 174 "escaped and quoted arguments each", | |
| 175 "foo 1 'Hello, \\'Tommy\\'!' ;" + | |
| 176 "bar Hi!\\ How\\ are\\ you? http://example.com", | |
| 177 [["foo", "1", "Hello, 'Tommy'!"], | |
| 178 ["bar", "Hi! How are you?", "http://example.com"]] | |
| 179 ); | |
| 180 checkParsedScript("Script with command names containing " + | |
| 181 "whitespace (spaces, tabs, newlines, etc.), " + | |
| 182 "quotes, and semicolons", | |
| 183 "fo\\'\\ \\ \\\t\\\n\\;o 1 2 3; 'b a r' 1 2", | |
| 184 [["fo' \t\n;o", "1", "2", "3"], ["b a r", "1", "2"]]); | |
| 185 checkParsedScript("Script containing Unicode composite characters", | |
| 186 "f\ud83d\ude42\ud83d\ude42 b\ud83d\ude02r", | |
| 187 [["f\ud83d\ude42\ud83d\ude42", "b\ud83d\ude02r"]]); | |
| 188 checkParsedScript("Script with no-op commands", "foo; ;;; ; ; bar 1", | |
| 189 [["foo"], ["bar", "1"]]); | |
| 190 | |
| 191 test.done(); | |
| 192 }; | |
| OLD | NEW |