Skip to content

feat(tags): trim tags and add validation before adding them - #1005

Merged
pbleser-oc merged 2 commits into
opencloud-eu:mainfrom
pbleser-oc:feat/tag-length-validation
Nov 16, 2026
Merged

pbleser-oc merged 2 commits into
opencloud-eu:mainfrom
pbleser-oc:feat/tag-length-validation

Conversation

@pbleser-oc

Copy link
Copy Markdown
Member

Tags are now trimmed before they are added or removed, and a new AddValidated lets callers check tags, e.g. their length, before they are stored. A new graph capability tags.max_tag_length tells clients the limit.

Changes

  • Normalization (pkg/tags): New, Add and Remove split the input on the separator, trim whitespace around each tag and drop empty tags.
    • " work" and "work" are now the same tag, and "a, ,b" no longer stores an empty tag.
    • Trimming covers all Unicode whitespace, plus the invisible zero-width space, word joiner and zero-width no-break space, which would otherwise make a tag look exactly like another one.
  • AddValidated(validator, tags...) works like Add, but first passes the normalized tags to validator and adds nothing if it returns an error.
  • MaxLengthValidator(maxTagLength) returns a validator that rejects tags longer than maxTagLength characters (Unicode code points, not bytes) and tags that aren't valid UTF-8. Its error lists all offending tags. A limit of 0 or less means no limit.
  • Capability: CapabilitiesGraph gets Tags with MaxTagLength (graph.tags.max_tag_length), so clients can check the length before sending a tag.

Behaviour change

Because of the trimming, Add, Remove and the stored tags change for tags with surrounding whitespace:

  • A tag stored as " work" before is now found and removed by "work".
  • Adding "work " when "work" exists is no longer a new tag.

In opencloud, pkg/tags is used by graph (tag assignment) and by search and webdav. They pick this up with the reva bump. Their tests pass with this branch: graph, search and webdav, built against it with a go.work.

Follow-up

The opencloud PR that bumps reva will use AddValidated with MaxLengthValidator when tags are assigned (400 on overlong tags), make the limit configurable, and set the capability.

AI assistance: Claude Code (claude-opus-5-5) wrote the code and the tests, and the first draft of this description; I reviewed them.

Tags are now normalized before they are added or removed: whitespace
around each tag is removed and empty tags are dropped, so " work" and
"work" are the same tag, and a list such as "a, ,b" no longer stores an
empty tag. This covers all Unicode whitespace, and also the invisible
zero-width space, word joiner and zero-width no-break space, which would
otherwise make a tag look exactly like another one.

AddValidated works like Add, but passes the normalized tags to a
validator first and adds nothing if it returns an error.
MaxLengthValidator returns such a validator that rejects tags longer
than a given number of characters (counted in Unicode code points) and
tags that are not valid UTF-8, and lists all offending tags in its
error.

The new graph capability tags.max_tag_length lets clients know the
limit before they send a tag.

Assisted-by: Claude Code:claude-opus-5-5
Comment thread pkg/owncloud/ocs/capabilities.go Resolved
The graph tags capability is always sent, so a server that doesn't set the
limit reports 0. Say in the doc comment that 0 means no limit, so that
clients don't reject every tag.

Assisted-by: Claude Code:claude-opus-5-5

@asaah262 asaah262 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Just left one small, non-blocking question.

@pbleser-oc
pbleser-oc merged commit e972bd4 into opencloud-eu:main Nov 16, 2026
19 checks passed
@openclouders openclouders mentioned this pull request Nov 13, 2026
1 task
pbleser-oc added a commit to pbleser-oc/opencloud that referenced this pull request Nov 16, 2026
Brings in the tag normalization and length validation of
opencloud-eu/reva#1005 (tags.AddValidated,
tags.MaxLengthValidator, the graph.tags capability). The only other
change since 036856689 is the backport configuration of the reva
repository.

Assisted-by: Claude Code:claude-opus-5-5
@pbleser-oc
pbleser-oc deleted the feat/tag-length-validation branch November 16, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants