mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 13:36:48 +00:00
1ad2e92142
The bulk of what SonarQube still had open on the reliability side, read site by
site rather than swept. Two clusters are worth calling out because they are
defects, not lint.
**Four regexes could be made to hang the process.** The worst is
`/.+@.+\..+/` in the forgot-password path: three unbounded `.+` that all
overlap, unanchored, on an endpoint that needs no login and whose schema is a
bare z.string() under a 100kb body cap. A thousand '@' characters had not
finished after 100 seconds — one request pins the event loop, and Node has one.
EMAIL_REGEX in auth.helpers is the same shape on register and profile update
(310ms for 8kb). The two tag strippers over an uploaded KML description and over
Commons metadata took 0.52s on a 16k run of '<'. Each rewrite was proven
equivalent by brute force against the original — millions of strings for the
coordinate patterns, 671,876 for the tag stripper — because a subtly different
regex on a parsing path is worse than the finding.
`<[^>]+>` could not be fixed in the pattern: `[^>]` matches `<` too, so the only
unambiguous form changes what happens to malformed markup. It is now a scan in
common/stripHtmlTags.ts, quirks included — `<>` is left alone, `<a<b>` is one
tag — with the equivalence pinned by a test that compares against the old regex
over every string up to length six.
**And roughly 500 places could only be reached with a mouse.** Clickable divs
became real buttons where the markup allowed (52 of them), took
role + tabIndex + Enter/Space where they had to stay divs, and modal backdrops
took role="presentation" — the honest role, since a backdrop is a mouse shortcut
for a Cancel control that is already in the tab order, and making it a button
plants a nameless full-screen tab stop around its own contents.
Alongside those: `.sort()` calls that now say the order they always had, `{n &&
<X/>}` guards that rendered a literal "0" for a zero-byte file and for a place at
latitude 0, an optimistic budget write that stored a boolean where the contract
and both transports use 0/1, and the Number statics.
sonar-project.properties documents the six that were deliberately left: two wiki
patterns with no overlapping quantifier pair whose "fix" would stop parsing
`[see [1]](url)`, four tar header fields bounded at 12-155 bytes by the format,
two djb2 hashes where the 32-bit wrap is the algorithm, two `| 0` that are also
coercing undefined to 0 on a path where the API sends no user_id, and the MCP
session maps Sonar reads as empty because they are filled from another module.
104 lines
3.2 KiB
TypeScript
104 lines
3.2 KiB
TypeScript
import React, { useEffect, useCallback } from 'react'
|
|
import { createPortal } from 'react-dom'
|
|
import { AlertTriangle } from 'lucide-react'
|
|
import { useTranslation } from '../../i18n'
|
|
|
|
interface ConfirmDialogProps {
|
|
isOpen: boolean
|
|
onClose: () => void
|
|
onConfirm: () => void
|
|
title?: string
|
|
message?: string
|
|
confirmLabel?: string
|
|
cancelLabel?: string
|
|
danger?: boolean
|
|
}
|
|
|
|
// Callers commonly pass an async handler that reports its own failure and then
|
|
// rethrows. The dialog has already closed at that point, so the rejection would
|
|
// escape as an unhandled promise — absorb it here.
|
|
function runConfirm(onConfirm: () => void): void {
|
|
const result = onConfirm() as unknown
|
|
if (result && typeof (result as PromiseLike<unknown>).then === 'function') {
|
|
void Promise.resolve(result).catch(() => {})
|
|
}
|
|
}
|
|
|
|
export default function ConfirmDialog({
|
|
isOpen,
|
|
onClose,
|
|
onConfirm,
|
|
title,
|
|
message,
|
|
confirmLabel,
|
|
cancelLabel,
|
|
danger = true,
|
|
}: ConfirmDialogProps) {
|
|
const { t } = useTranslation()
|
|
|
|
const handleEsc = useCallback((e: KeyboardEvent) => {
|
|
if (e.key === 'Escape') onClose()
|
|
}, [onClose])
|
|
|
|
useEffect(() => {
|
|
if (isOpen) {
|
|
document.addEventListener('keydown', handleEsc)
|
|
}
|
|
return () => document.removeEventListener('keydown', handleEsc)
|
|
}, [isOpen, handleEsc])
|
|
|
|
if (!isOpen) return null
|
|
|
|
return createPortal(
|
|
<div
|
|
// Backdrop only — Escape (above) and the Cancel button below are the
|
|
// keyboard routes out of the dialog.
|
|
role="presentation"
|
|
className="fixed inset-0 z-[10000] flex items-center justify-center px-4 trek-backdrop-enter bg-[rgba(15,23,42,0.5)]"
|
|
style={{ paddingBottom: 'var(--bottom-nav-h)' }}
|
|
onClick={onClose}
|
|
>
|
|
<div
|
|
role="presentation"
|
|
className="trek-modal-enter rounded-2xl shadow-2xl w-full max-w-sm p-6 bg-surface-card"
|
|
onClick={e => e.stopPropagation()}
|
|
>
|
|
<div className="flex items-start gap-4">
|
|
{danger && (
|
|
<div className="flex-shrink-0 w-10 h-10 rounded-full bg-red-100 flex items-center justify-center">
|
|
<AlertTriangle className="w-5 h-5 text-red-600" />
|
|
</div>
|
|
)}
|
|
<div className="flex-1">
|
|
<h3 className="text-base font-semibold text-content">
|
|
{title || t('common.confirm')}
|
|
</h3>
|
|
<p className="mt-1 text-sm text-content-secondary">
|
|
{message}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="flex justify-end gap-3 mt-6">
|
|
<button type="button"
|
|
onClick={onClose}
|
|
className="px-4 py-2 text-sm font-medium rounded-lg transition-colors text-content-secondary border border-edge-secondary"
|
|
>
|
|
{cancelLabel || t('common.cancel')}
|
|
</button>
|
|
<button type="button"
|
|
onClick={() => { runConfirm(onConfirm); onClose() }}
|
|
className={`px-4 py-2 text-sm font-medium rounded-lg transition-colors text-white ${
|
|
danger ? 'bg-red-600 hover:bg-red-700' : 'bg-blue-600 hover:bg-blue-700'
|
|
}`}
|
|
>
|
|
{confirmLabel || t('common.delete')}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
</div>,
|
|
document.body
|
|
)
|
|
}
|