Skip to content

Parser duplicates the prefix-modifier range rule instead of using UriTemplateVarSpec constants #67

Description

@brenpike

Spun out of #30 so that tracking issue can be closed. #30's own acceptance criteria are met; this was listed there as deferred follow-up work — and the duplication it anticipated did in fact materialize.

Problem

The prefix-modifier range rule is expressed twice.

UriTemplateVarSpec defines the bounds as named constants and validates against them:

  • src/Chatter.Rest.UriTemplates/UriTemplateVarSpec.cs:39internal const int MaxPrefixLength = 9999;
  • :99if (length < MinPrefixLength || length > MaxPrefixLength)

UriTemplateParser re-implements the same rule with hardcoded literals:

  • src/Chatter.Rest.UriTemplates/UriTemplateParser.cs:134if (!int.TryParse(suffix, out var prefixLen) || prefixLen < 1 || prefixLen > 9999)
  • :112 and :137 — the bounds are also spelled out in the message text

The two agree today. Nothing enforces that they keep agreeing.

Requested change

Have UriTemplateParser use UriTemplateVarSpec.MinPrefixLength / MaxPrefixLength rather than literals, and interpolate them into the exception messages so the text cannot drift from the check either.

Behavior-preserving refactor; no observable change, no version bump beyond whatever the touched src/ path already requires per CLAUDE.md.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions