From 613699fb695671ea7e7ae63ac6a9bda0384a2a46 Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Sat, 30 Sep 2023 01:44:54 +0530 Subject: [PATCH] fix(#248): gracefully abort cm header hint when word match fails --- .../bruno-app/src/components/SingleLineEditor/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/bruno-app/src/components/SingleLineEditor/index.js b/packages/bruno-app/src/components/SingleLineEditor/index.js index 3b786ca93..4f1575bca 100644 --- a/packages/bruno-app/src/components/SingleLineEditor/index.js +++ b/packages/bruno-app/src/components/SingleLineEditor/index.js @@ -10,7 +10,7 @@ const SERVER_RENDERED = typeof navigator === 'undefined' || global['PREVENT_CODE if (!SERVER_RENDERED) { CodeMirror = require('codemirror'); CodeMirror.registerHelper('hint', 'anyword', (editor, options) => { - const word = /[\w$]+/; + const word = /[\w$-]+/; const wordlist = (options && options.autocomplete) || []; let cur = editor.getCursor(), curLine = editor.getLine(cur.line); @@ -19,6 +19,11 @@ if (!SERVER_RENDERED) { while (start && word.test(curLine.charAt(start - 1))) --start; let curWord = start != end && curLine.slice(start, end); + // Check if curWord is a valid string before proceeding + if (typeof curWord !== 'string' || curWord.length < 3) { + return null; // Abort the hint + } + const list = (options && options.list) || []; const re = new RegExp(word.source, 'g'); for (let dir = -1; dir <= 1; dir += 2) {