+18
-9
lines changedFilter options
+18
-9
lines changed Original file line number Diff line number Diff line change
@@ -230,17 +230,26 @@
230
230
toInject.set(rawToken, content);
231
231
};
232
232
233
-
// Fill template placeholders. Return falsy if:
234
-
// - At least one argument contains anything else than /\w/ and `.`
235
-
233
+
// Fill-in scriptlet argument placeholders.
236
234
const patchScriptlet = function(content, args) {
235
+
let s = args;
236
+
let len = s.length;
237
+
let beg = 0, pos = 0;
237
238
let i = 1;
238
-
while ( args !== '' ) {
239
-
let pos = args.indexOf(',');
240
-
if ( pos === -1 ) { pos = args.length; }
241
-
const arg = args.slice(0, pos).trim().replace(reEscapeScriptArg, '\\$&');
242
-
content = content.replace(`{{${i}}}`, arg);
243
-
args = args.slice(pos + 1).trim();
239
+
while ( beg < len ) {
240
+
pos = s.indexOf(',', pos);
241
+
// Escaped comma? If so, skip.
242
+
if ( pos > 0 && s.charCodeAt(pos - 1) === 0x5C /* '\\' */ ) {
243
+
s = s.slice(0, pos - 1) + s.slice(pos);
244
+
len -= 1;
245
+
continue;
246
+
}
247
+
if ( pos === -1 ) { pos = len; }
248
+
content = content.replace(
249
+
`{{${i}}}`,
250
+
s.slice(beg, pos).trim().replace(reEscapeScriptArg, '\\$&')
251
+
);
252
+
beg = pos = pos + 1;
244
253
i++;
245
254
}
246
255
return content;
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4