carlos / platform Public

console: DPA single-line fields drop U+2028 and U+2029

dpaField dropped control and bidi characters but kept the line and
paragraph separators, where a renderer may break a single-line value.
They are now dropped in single-line fields; the address keeps its line
breaks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 99d6cdbc0553f76f9d284308e897dc9eb9d1398e parent 699d721
2 files changed, +26 −2
  • internal/console/dpapane.go +4 −2
  • internal/console/dpapane_test.go +22 −0
diff --git a/internal/console/dpapane.go b/internal/console/dpapane.go
index 09cd74c6e..c9ed5dde6 100644
--- a/internal/console/dpapane.go
+++ b/internal/console/dpapane.go
@@ -232,14 +232,16 @@ func (s *Server) dpaPaneFor(ctx context.Context, p *page, acct *Account, role st
}
// dpaField is a form value trimmed and with control characters dropped (a
-// line break kept only when lines is set), and its error message, if any.
+// line break kept only when lines is set), and its error message, if any. A
+// single-line field also drops U+2028 and U+2029, where a renderer may break
+// the line.
func dpaField(v string, max int, lines bool) (string, string) {
v = strings.ToValidUTF8(strings.ReplaceAll(v, "\r\n", "\n"), "")
v = strings.Map(func(r rune) rune {
switch {
case r == '\n' && lines:
return r
- case unicode.IsControl(r), dpaBidiControl(r):
+ case unicode.IsControl(r), dpaBidiControl(r), !lines && (r == '\u2028' || r == '\u2029'):
return -1
}
return r
diff --git a/internal/console/dpapane_test.go b/internal/console/dpapane_test.go
index f13358590..b0f351565 100644
--- a/internal/console/dpapane_test.go
+++ b/internal/console/dpapane_test.go
@@ -705,3 +705,25 @@ func dpaCurrentLetterhead(t *testing.T, fx *consoleFixture) *Letterhead {
}
return lh
}
+
+// TestDPAFieldLineSeparators: a single-line field drops U+2028 and U+2029
+// (a renderer may break the line there) with the other control and format
+// characters; the address keeps its real line breaks.
+func TestDPAFieldLineSeparators(t *testing.T) {
+ for _, tc := range []struct {
+ in string
+ lines bool
+ want string
+ }{
+ {"Shop
Limited", false, "ShopLimited"},
+ {"Shop
Limited", false, "ShopLimited"},
+ {"Shop‮Limited\u0007", false, "ShopLimited"},
+ {"Shop\nLimited", false, "ShopLimited"},
+ {"1 Main Street\r\nDublin", true, "1 Main Street\nDublin"},
+ {"1 Main Street\n\n Dublin ", true, "1 Main Street\nDublin"},
+ } {
+ if got, msg := dpaField(tc.in, 200, tc.lines); got != tc.want || msg != "" {
+ t.Errorf("dpaField(%q, lines=%v) = %q %q, want %q", tc.in, tc.lines, got, msg, tc.want)
+ }
+ }
+}