Skip to content

Conversation

@arianf
Copy link

@arianf arianf commented Jan 31, 2026

Enforce size limit when paged searches are enabled

Fixes the :size option being ignored when paged searches are enabled and the requested size exceeds 126.

Problem

When paging is enabled and remaining entries needed exceeds 126, the code sets query_limit = 0 (no server-side limit) to avoid conflicts with the page size. However, the limit is never enforced client-side.

The existing code comment acknowledges this:

"(Because we pass zero as the sizelimit on search rounds when the remaining limit is larger than our max page size of 126. In these cases, I think the caller's search limit will be ignored!)"

Solution

Add a client-side check to break the paging loop when the requested size limit is reached:

break if size > 0 && n_results >= size

Related Issues

Testing

Tested against a production LDAP server with 5900+ entries matching the filter.
Before: all 5900+ returned.
After: exactly 3000 as requested.

Checklist

  • Fix applied to lib/net/ldap/connection.rb
  • Add unit test for size limit with paged searches
  • Update History.rdoc with change summary
  • Run full test suite (bundle exec rake)

When paging is enabled and the requested size exceeds 126, the client now
correctly stops fetching additional pages once the size limit is reached.
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.

1 participant