picocrank 1.22.0 → 1.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "picocrank",
3
- "version": "1.22.0",
3
+ "version": "1.22.1",
4
4
  "description": "A set of zero dependency Vue components built on the Femtocrank global CSS theme.",
5
5
  "main": "vite.config.js",
6
6
  "scripts": {
@@ -362,11 +362,35 @@ function selectItem(item) {
362
362
  close()
363
363
  }
364
364
 
365
+ function escapeHtml(value) {
366
+ return String(value)
367
+ .replace(/&/g, '&')
368
+ .replace(/</g, '&lt;')
369
+ .replace(/>/g, '&gt;')
370
+ .replace(/"/g, '&quot;')
371
+ .replace(/'/g, '&#39;')
372
+ }
373
+
365
374
  function highlightText(text, query) {
366
- if (!query || !text) return text
375
+ if (text == null || text === '') return ''
376
+
377
+ const source = String(text)
378
+ if (!query) return escapeHtml(source)
379
+
380
+ const regex = new RegExp(query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi')
381
+ let result = ''
382
+ let lastIndex = 0
383
+
384
+ for (const match of source.matchAll(regex)) {
385
+ const start = match.index
386
+ const matched = match[0]
387
+ result += escapeHtml(source.slice(lastIndex, start))
388
+ result += `<mark>${escapeHtml(matched)}</mark>`
389
+ lastIndex = start + matched.length
390
+ }
367
391
 
368
- const regex = new RegExp(`(${query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')})`, 'gi')
369
- return text.replace(regex, '<mark>$1</mark>')
392
+ result += escapeHtml(source.slice(lastIndex))
393
+ return result
370
394
  }
371
395
 
372
396
  function addItem(item) {