util/SafePathComponent.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | // S106-198/S106-234: an identifier that becomes one component of a file | ||
| 3 | // name or directory (account ids under sieve/<id>, keyring names, draft | ||
| 4 | // slot names) — not empty, not "." or "..", no separator, no control | ||
| 5 | // character, at most 128 characters. Header-only and pure. | ||
| 6 | |||
| 7 | #include <QChar> | ||
| 8 | #include <QString> | ||
| 9 | |||
| 10 | namespace SafePathComponent { | ||
| 11 | |||
| 12 | 1874 | inline bool isSafe(const QString &id) { | |
| 13 |
8/10✓ Branch 3 → 4 taken 1873 times.
✓ Branch 3 → 12 taken 1 time.
✓ Branch 5 → 6 taken 1873 times.
✗ Branch 5 → 12 not taken.
✓ Branch 8 → 9 taken 1873 times.
✗ Branch 8 → 12 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 13 taken 1872 times.
✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 16 taken 1872 times.
|
1874 | if (id.isEmpty() || id.size() > 128 || id == QLatin1String(".") || id == QLatin1String("..")) |
| 14 | 2 | return false; | |
| 15 |
2/2✓ Branch 33 → 18 taken 33469 times.
✓ Branch 33 → 34 taken 1866 times.
|
35335 | for (const QChar c : id) |
| 16 |
6/8✓ Branch 21 → 22 taken 33463 times.
✓ Branch 21 → 28 taken 6 times.
✓ Branch 25 → 26 taken 33463 times.
✗ Branch 25 → 28 not taken.
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 33463 times.
✓ Branch 30 → 31 taken 6 times.
✓ Branch 30 → 32 taken 33463 times.
|
33469 | if (c == QLatin1Char('/') || c == QLatin1Char('\\') || c.category() == QChar::Other_Control) |
| 17 | 6 | return false; | |
| 18 | 1866 | return true; | |
| 19 | } | ||
| 20 | |||
| 21 | } // namespace SafePathComponent | ||
| 22 |