diff options
Diffstat (limited to 'modules/core/core-bundle.js')
| -rw-r--r-- | modules/core/core-bundle.js | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/modules/core/core-bundle.js b/modules/core/core-bundle.js index df4563d..a5e9a79 100644 --- a/modules/core/core-bundle.js +++ b/modules/core/core-bundle.js @@ -824,7 +824,10 @@ class VirtualFileSystem { dir = resolved.dir; } const results = []; - const regex = new RegExp(pattern, 'i'); + // v4.6.64: an invalid pattern must not throw into the error ledger (packet §8). + let regex; + try { regex = new RegExp(pattern, 'i'); } + catch (e) { this._lastPatternError = e.message; return []; } for (const name of Object.keys(dir.content)) { const fullPath = path ? path + '/' + name : name; if (regex.test(name)) { @@ -838,7 +841,10 @@ class VirtualFileSystem { } grep(pattern, path = '') { const results = []; - const regex = new RegExp(pattern, 'i'); + // v4.6.64: see find() above — a bad pattern is a result, not an exception. + let regex; + try { regex = new RegExp(pattern, 'i'); } + catch (e) { this._lastPatternError = e.message; return []; } const files = this.find('.', path).filter(e => e.type === 'file'); for (const file of files) { const content = this.readFile(file.path); @@ -6636,7 +6642,16 @@ class FileSystemModule { } const pattern = args[ai]; const target = args[ai + 1]; if (!pattern) return this.terminal.print('Usage: grep [-n] [-i] [-c] [-l] <pattern> [filename]', 'warning'); - const re = new RegExp(pattern, opt.ignoreCase ? 'i' : ''); + // v4.6.64: an invalid pattern is user input, not a system fault. It used to throw + // out of the command handler into the error ledger, polluting the counter that + // packet §2 says nobody can trust (packet §8). + let re; + try { + re = new RegExp(pattern, opt.ignoreCase ? 'i' : ''); + } catch (e) { + this.terminal.print('grep: invalid pattern: ' + pattern + ' (' + e.message + ')', 'warning'); + return; + } const hits = (line) => (opt.invert ? !re.test(line) : re.test(line)); if (target) { const c = this.terminal.fs.readFile(target); |