stringsx

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package stringsx applies opt-in string sanitization rules declared via the (platform.strings.v1.string_rules) field option, ported from taply's strutil package.

Apply walks a request message, finds string fields annotated with string_rules, and applies the configured transformations in a fixed order:

  1. strip_control — remove \x00-\x1F (except \t \n \r), zero-width, BOM
  2. nfc — Unicode NFC normalization
  3. trim — TrimSpace (leading and trailing)
  4. collapse_spaces — collapse runs of whitespace to a single ASCII space
  5. lowercase OR uppercase
  6. nullify_empty — clear the field when the result is "" (proto3 optional only)

It must run BEFORE idempotency and validation, so that:

  • the idempotency fingerprint is computed on the canonical form (so "Burger" and "Burger " produce the same hash),
  • protovalidate rules like min_len see the trimmed value (so whitespace-only input fails validation as expected).

The api module does this when it is given the function: api.Normalize(app, stringsx.Apply).

Index

Constants

This section is empty.

Variables

View Source
var Proto string

Proto is the source of the string_rules option: a project that annotates its fields needs it next to its own proto files as platform/strings/v1/strings.proto, so the descriptors of both are the same file.

Functions

func Apply

func Apply(msg proto.Message)

Apply walks the given proto message and applies string_rules to annotated fields. It is the function api.Normalize takes.

Types

This section is empty.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL