Fix cleanupText (#2138)

Fixes a bug with our cleanupText helper where it fails on the empty
string or string with only space character(s).

Fixes https://tldraw.sentry.io/issues/4593272987

### Change Type

- [x] `patch` — Bug fix


[^1]: publishes a `patch` release, for devDependencies use `internal`
[^2]: will not publish a new version

### Test Plan

1. Add a step-by-step description of how to test your PR here.
2.

- [x] Unit Tests
- [ ] End to end tests

### Release Notes

- Fixes a minor bug where cleaning up text would fail.
pull/2144/head
David Sheldrick 2023-11-01 16:02:42 +00:00 zatwierdzone przez GitHub
rodzic 5719cc76c1
commit 8a1b014b02
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 12 dodań i 1 usunięć

Wyświetl plik

@ -0,0 +1,11 @@
import { cleanupText } from './text'
describe(cleanupText, () => {
it('can handle the empty string', () => {
expect(cleanupText('')).toBe('')
})
it('can handle space-only strings', () => {
expect(cleanupText(' ')).toBe('')
expect(cleanupText(' ')).toBe('')
})
})

Wyświetl plik

@ -24,7 +24,7 @@ function stripCommonMinimumIndentation(text: string): string {
const lines = text.split('\n')
// remove any leading lines that are only whitespace or newlines
while (lines[0].trim().length === 0) {
while (lines[0] && lines[0].trim().length === 0) {
lines.shift()
}