From 587b768c7cee6c68a04a369376155b2e2ff5a1f5 Mon Sep 17 00:00:00 2001 From: Yadhav Jayaraman <57544838+decyjphr@users.noreply.github.com> Date: Tue, 27 Aug 2024 09:50:41 -0400 Subject: [PATCH] fix alerts --- lib/glob.js | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/lib/glob.js b/lib/glob.js index beeb1ada..9a85f220 100644 --- a/lib/glob.js +++ b/lib/glob.js @@ -1,28 +1,40 @@ class Glob { - constructor (glob) { - this.glob = glob - const regexptex = glob.replace(/\//g, '\\/').replace(/\?/g, '([^\\/])').replace(/\./g, '\\.').replace(/\*/g, '([^\\/]*)') - this.regexp = new RegExp(`^${regexptex}$`, 'u') + constructor(glob) { + this.glob = glob; + + // If not a glob pattern then just match the string. + if (!this.glob.includes("*")) { + this.regexp = new RegExp(`.*${glob}.*`, "u"); + return; + } + const regexptex = this.glob + .replace(/\\/g, "\\\\") + .replace(/\//g, "\\/") + .replace(/\?/g, "([^\\/])") + .replace(/\./g, "\\.") + .replace(/\*\*/g, ".+") + .replace(/\*/g, "([^\\/]*)"); + this.regexp = new RegExp(`^${regexptex}$`, "u"); } - toString () { - return this.glob + toString() { + return this.glob; } - [Symbol.search] (s) { - return s.search(this.regexp) + [Symbol.search](s) { + return s.search(this.regexp); } - [Symbol.match] (s) { - return s.match(this.regexp) + [Symbol.match](s) { + return s.match(this.regexp); } - [Symbol.replace] (s, replacement) { - return s.replace(this.regexp, replacement) + [Symbol.replace](s, replacement) { + return s.replace(this.regexp, replacement); } - [Symbol.replaceAll] (s, replacement) { - return s.replaceAll(this.regexp, replacement) + [Symbol.replaceAll](s, replacement) { + return s.replaceAll(this.regexp, replacement); } } -module.exports = Glob +module.exports = Glob;