Skip to content

Commit 801df8b

Browse files
Independent Panel: Polish search input and key binding
Sanitize search input by removing control chars (incl. DEL) and truncating at 500 code points; keep Tab/LF/CR intact Bind keyboard shortcut handler once (remove [collapsed] dependency) to avoid unnecessary rebinds; no behavior change Motivation: Improve stability for pasted or edge inputs and simplify listener lifecycle without altering the intended UX
1 parent 51472c2 commit 801df8b

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/pages/IndependentPanel/App.jsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,20 @@ function App() {
124124

125125
const handleSearchChange = (e) => {
126126
const raw = e?.target?.value ?? ''
127-
// Keep Tab/LF/CR and printable range; strip other control chars
128-
const cleaned = raw.replace(/[^\t\n\r\x20-\uFFFF]/g, '').slice(0, 500)
129-
setSearchQuery(cleaned)
127+
// Keep Tab/LF/CR, remove other control chars (incl. DEL), then truncate by code points
128+
const CP_TAB = 9
129+
const CP_LF = 10
130+
const CP_CR = 13
131+
const CP_PRINTABLE_MIN = 32
132+
const CP_DEL = 127
133+
const isAllowedCodePoint = (cp) =>
134+
cp === CP_TAB || cp === CP_LF || cp === CP_CR || (cp >= CP_PRINTABLE_MIN && cp !== CP_DEL)
135+
const sanitizedArr = Array.from(raw).filter((ch) => {
136+
const cp = ch.codePointAt(0)
137+
return cp != null && isAllowedCodePoint(cp)
138+
})
139+
const limited = sanitizedArr.slice(0, 500).join('')
140+
setSearchQuery(limited)
130141
}
131142

132143
// Debounce search input for performance
@@ -166,7 +177,7 @@ function App() {
166177
}
167178
window.addEventListener('keydown', onKeyDown)
168179
return () => window.removeEventListener('keydown', onKeyDown)
169-
}, [collapsed])
180+
}, [])
170181

171182
// Utility function to safely convert any value to a string
172183
const toSafeString = (value) =>

0 commit comments

Comments
 (0)