fix(importer): clamp over-long external text fields so imports do not hard-fail (#15) #37

Merged
jmz merged 6 commits from fix/waypoint-description-clamp into main 2026-10-31 14:28:32 +00:00
Owner

Problem (fixes #15)

The importer wrote external strings straight into records and app.Save aborts the entire trail import on any field-validation error. Reported case: a GPX waypoint description over the waypoints collection's 5000-char limit (komoot POI descriptions routinely run 5-6.5k) killed the whole trail. The same failure mode applies to the other external text the importer writes — the waypoint name and the trail name/description — so over-long values there abort imports too (confirmed for waypoint name: name: Must be no more than 255 character(s)).

Fix

Add clampTextField(collection, field, value) — clamps to that field's own rune limit (read from the collection, no-op for unbounded/non-text fields), rune-safe with an ellipsis. Apply it to every external text field createWaypoints and ImportTrail write (waypoint name+description, trail name+description). Mirrors the existing photoFiles skip-don't-fail philosophy: no single over-long external value can abort an import.

Tests (test-first)

  • TestCreateWaypointsClampsOverlongDescription — 6000-rune description; reproduced the exact abort before the fix.
  • TestCreateWaypointsClampsOverlongName — 600-char name; reproduced name: Must be no more than 255 character(s) before the fix.
  • TestClampToRuneLimit — table test (empty, under/at/over limit, multibyte, no-limit).
  • Full plugins/importer suite + go vet + go build ./... green (CGO_ENABLED=0, go 1.25).

Atomic, upstreamable. AI-assisted, disclosed (Co-Authored-By).

## Problem (fixes #15) The importer wrote external strings straight into records and `app.Save` **aborts the entire trail import** on any field-validation error. Reported case: a GPX waypoint description over the `waypoints` collection's 5000-char limit (komoot POI descriptions routinely run 5-6.5k) killed the whole trail. The **same failure mode** applies to the other external text the importer writes — the waypoint **name** and the trail **name/description** — so over-long values there abort imports too (confirmed for waypoint name: `name: Must be no more than 255 character(s)`). ## Fix Add `clampTextField(collection, field, value)` — clamps to that field's **own** rune limit (read from the collection, no-op for unbounded/non-text fields), rune-safe with an ellipsis. Apply it to every external text field `createWaypoints` and `ImportTrail` write (waypoint name+description, trail name+description). Mirrors the existing `photoFiles` skip-don't-fail philosophy: no single over-long external value can abort an import. ## Tests (test-first) - `TestCreateWaypointsClampsOverlongDescription` — 6000-rune description; reproduced the exact abort before the fix. - `TestCreateWaypointsClampsOverlongName` — 600-char name; reproduced `name: Must be no more than 255 character(s)` before the fix. - `TestClampToRuneLimit` — table test (empty, under/at/over limit, multibyte, no-limit). - Full `plugins/importer` suite + `go vet` + `go build ./...` green (CGO_ENABLED=0, go 1.25). Atomic, upstreamable. AI-assisted, disclosed (Co-Authored-By).
jmz changed title from fix(importer): clamp over-long waypoint descriptions instead of failing the import to fix(importer): clamp over-long external text fields so imports do not hard-fail (#15) 2026-09-08 13:44:36 +00:00
jmz force-pushed fix/waypoint-description-clamp from 8aa3465565
Some checks failed
Go / db-test (pull_request) Failing after 2s
to d45b7875e9
Some checks failed
CI / go (push) Has been cancelled
CI / web (push) Has been cancelled
2026-10-30 23:34:28 +00:00
Compare
maximus changed target branch from main to main-v0.21.2 2026-10-30 23:34:47 +00:00
Member

Phase-1 catch-up review (upstream v0.21.2)

Rebased onto main-v0.21.2, with the base retargeted. The old head is kept as archive/fix-waypoint-description-clamp-pre-v0.21.2.

Upstream fixed half of #15 in v0.21.1. #1320 added util.SanitizeHTMLFieldsWithLimits(record) to ImportTrail and createWaypoints. It shortens the rich-text description fields (trails, waypoints) to the field limit and is HTML-aware. Clamping the raw HTML first could cut a tag in half, so I added d45b7875:

  • Only the plain-text name fields are clamped now.
  • The description test is kept as a regression guard for #15. Its ellipsis assertion is dropped, because the sanitizer decides how to shorten.

The clamp helper and tests for names are correct: rune-safe, using the field's own Max, and a no-op for unbounded fields.

Not run: go vet/test (CI on the NAS runner was paused tonight, and the run was cancelled). The old CI failures (7465/7476) were the node24-vs-runner-v6 issue (log: "got node24"), not the tests.

Verdict: needs work, then upstream it. Merging it into the fork has no live effect, because prodesk runs the upstream flomp/wanderer-db image, not one built from this fork. Next steps:

  1. CI green.
  2. Retitle as "clamp over-long imported names".
  3. Open the upstream PR. The name overflow (name: Must be no more than 255 character(s)) is still unhandled upstream as of v0.21.2.

🤖 Generated with Claude Code

https://claude.ai/code/session_01M1AaXnEghenJ4BDxNryKvs

## Phase-1 catch-up review (upstream v0.21.2) **Rebased** onto `main-v0.21.2`, with the base retargeted. The old head is kept as `archive/fix-waypoint-description-clamp-pre-v0.21.2`. **Upstream fixed half of #15 in v0.21.1.** #1320 added `util.SanitizeHTMLFieldsWithLimits(record)` to `ImportTrail` and `createWaypoints`. It shortens the rich-text `description` fields (trails, waypoints) to the field limit and is HTML-aware. Clamping the raw HTML first could cut a tag in half, so I added `d45b7875`: - Only the plain-text `name` fields are clamped now. - The description test is kept as a regression guard for #15. Its ellipsis assertion is dropped, because the sanitizer decides how to shorten. The clamp helper and tests for names are correct: rune-safe, using the field's own `Max`, and a no-op for unbounded fields. **Not run:** go vet/test (CI on the NAS runner was paused tonight, and the run was cancelled). The old CI failures (7465/7476) were the node24-vs-runner-v6 issue (log: "got node24"), not the tests. **Verdict: needs work, then upstream it. Merging it into the fork has no live effect,** because prodesk runs the upstream `flomp/wanderer-db` image, not one built from this fork. Next steps: 1. CI green. 2. Retitle as "clamp over-long imported names". 3. Open the upstream PR. The name overflow (`name: Must be no more than 255 character(s)`) is still unhandled upstream as of v0.21.2. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01M1AaXnEghenJ4BDxNryKvs
fix(importer): clamp names at PocketBase's default limit when Max is 0
Some checks failed
CI / go (push) Failing after 2m54s
CI / web (push) Successful in 2m7s
ae14894ed2
The trails and waypoints name fields have TextField.Max = 0, which
PocketBase treats as its 5000-character default, but clampTextField
read Max = 0 as "no limit" and never clamped: on the real schema the
name clamp was a no-op and an over-long external name still failed the
import. Fall back to 5000 like util.SanitizeHTMLFieldsWithLimits does,
and test it against a Max 0 field (the earlier test used Max 255).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01M1AaXnEghenJ4BDxNryKvs
test(importer): pass the media log context added to createWaypoints in v0.21.2
All checks were successful
CI / go (push) Successful in 20m11s
CI / web (push) Successful in 1m40s
212909d21c
Upstream v0.21.2 added a pluginMediaLogContext parameter to createWaypoints;
the waypoint clamp tests still called it with the old arity, so `go vet`
failed to compile the package.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01M1AaXnEghenJ4BDxNryKvs
jmz changed target branch from main-v0.21.2 to main 2026-10-31 13:01:13 +00:00
Merge main (v0.21.2 + upstream-sync) into fix/waypoint-description-clamp
All checks were successful
CI / go (push) Successful in 23m50s
CI / web (push) Successful in 1m29s
9229f6f91c
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XMf4EKLnjYyjFp8QGWgFFq
jmz merged commit adab80a3dc into main 2026-10-31 14:28:32 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
public/wanderer!37
No description provided.