Skip to content

Fixes stray separators when expanding iterables with empty members - #3688

Merged
velo merged 1 commit into
OpenFeign:masterfrom
amalsaidov:fix-iterable-empty-member-expansion
Nov 16, 2026
Merged

velo merged 1 commit into
OpenFeign:masterfrom
amalsaidov:fix-iterable-empty-member-expansion

Conversation

@amalsaidov

Copy link
Copy Markdown
Contributor

Problem

Expressions.SimpleExpression.expandIterable decided where to place separators by inspecting the buffer built so far (result.toString().equalsIgnoreCase(this.separator)). That check only holds when at most one empty member has been seen, so lists that were empty or contained consecutive empty members leaked extra separators.

Simple expansion of /path/{ids}:

value before after (RFC 6570)
[""] /path/, /path/
["", "", "c"] /path/,,,c /path/,,c

Path-style expansion of {;ids} had the matching defect and also dropped the variable name on an empty member:

value before after
[""] ;; ;ids=
["a", ""] ;ids=a; ;ids=a;ids=

Fix

Replaced the buffer-inspection heuristic with a simple first-member flag. Members are now joined by exactly one separator, and an empty member expands to an empty string while still counting as a member, which matches RFC 6570 simple and path-style expansion.

Query parameters strip blank values before expansion (QueryTemplate filters with Util::isNotBlank), so the observable change is limited to path and path-style (;) expansion. Existing behavior for non-empty members and for a single leading empty member is unchanged.

Tests

Added two regression tests in UriTemplateTest covering simple and path-style expansion with empty members. Both fail on master and pass with this change. Verified locally with mvn -pl core test (template and request suites, JDK 25 toolchain).

AI-assisted; directed, reviewed and tested by the author (amalsaidov).

`SimpleExpression.expandIterable` tracked separators by inspecting the
buffer built so far, which miscounted once more than one empty member
was involved. Expanding a list that was empty or had consecutive empty
members leaked extra separators.

Examples (simple expansion of `{ids}`):
* `[""]` expanded to `,` instead of an empty string
* `["", "", "c"]` expanded to `,,,c` instead of `,,c`

Path-style (`{;ids}`) expansion had the matching defect, dropping the
variable name on empty members (`;ids=a;` instead of `;ids=a;ids=`).

Replaced the heuristic with a first-member flag so members are joined by
exactly one separator and an empty member expands to an empty string,
matching RFC 6570. Query parameters already strip blank values, so the
observable change is limited to path and path-style expansion.

Added regression tests in UriTemplateTest for both forms.

@velo velo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM - fixing stray separators when expanding iterables with empty members. Correct and well-tested.

@velo
velo enabled auto-merge (squash) November 16, 2026 10:57
@velo
velo merged commit e7d7ae8 into OpenFeign:master Nov 16, 2026
3 checks passed
@amalsaidov

Copy link
Copy Markdown
Contributor Author

Thanks for merging 🙏

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants