Skip to content

RideStatusCard: unify whitespace-trim idiom across driverName / vehicleDescription / chat label checks #87

@variablefate

Description

@variablefate

Background

PR #86 added two new presence checks to `RideStatusCard.swift` that defensively `trimmingCharacters(in: .whitespaces)` before an `isEmpty` test:

  • `vehicleDescriptionLabel` (`vehicleDescription` ViewBuilder)
  • `chatButtonLabelText` (chat button label helper)

The pre-existing `driverName` checks elsewhere in the same file do not trim:

```swift
if let driverName, !driverName.isEmpty {
Text("\(driverName) is on the way!")
...
}
```

Bug

A driver-name string of `" "` (three spaces — possible if a driver fat-fingered their Kind 0 profile) would render as e.g. `" is on the way!"` with a leading whitespace blob and no actual name. Today the path that produces `driverName` (`AppState.driverDisplayName(pubkey:)` → `driversRepository?.cachedDriverName(pubkey:)`) probably normalizes upstream, but it's a brittle invariant — the trimming should be at the leaf where it's used, not relied on upstream.

Why this matters

PR #86 set a precedent for the "trim-then-empty-check" idiom because the rider's view of a sloppily-filled driver profile is exactly the surface this matters on. It would be cleaner if all four sites used the same idiom rather than two of them being more defensive than the others.

Suggested fix

Extract a small private helper, e.g.:

```swift
private func nonBlank(_ s: String?) -> String? {
let trimmed = s?.trimmingCharacters(in: .whitespaces) ?? ""
return trimmed.isEmpty ? nil : trimmed
}
```

Use it at all four sites:

Optionally do the same for `pickupAddress` / `destinationAddress` in `rideSummaryCard` for symmetry.

Effort

XS — pure refactor, no behavior change for valid inputs. Add one Swift Testing case for the trim behavior on the existing `driverName` paths.

Out of scope for #86

Filed as a follow-up because PR #86 was scoped strictly to #79 + #80, and the pre-existing untrimmed checks predate that PR (blame: 4d3e7ec). Worth fixing as a small lower-entropy refactor on its own branch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions