Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 80b6df8

Browse files
authored
Merge pull request #1 from ldapjs/fix-search-req-scope
Fix SearchRequest scope property
2 parents 6652801 + c19fa65 commit 80b6df8

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

lib/messages/search-request.js

+23-11
Original file line numberDiff line numberDiff line change
@@ -284,21 +284,15 @@ class SearchRequest extends LdapMessage {
284284
}
285285

286286
/**
287-
* The current search scope value.
287+
* The current search scope value. Can be matched against the exported
288+
* scope statics.
288289
*
289-
* @returns {string}
290+
* @returns {number}
290291
*
291292
* @throws When the scope is set to an unrecognized scope constant.
292293
*/
293294
get scope () {
294-
switch (this.#scope) {
295-
case search.SCOPE_BASE_OBJECT:
296-
return 'base'
297-
case search.SCOPE_ONE_LEVEL:
298-
return 'single'
299-
case search.SCOPE_SUBTREE:
300-
return 'subtree'
301-
}
295+
return this.#scope
302296
}
303297

304298
/**
@@ -318,6 +312,24 @@ class SearchRequest extends LdapMessage {
318312
this.#scope = resolvedScope
319313
}
320314

315+
/**
316+
* The current search scope value as a string name.
317+
*
318+
* @returns {string} One of 'base', 'single', or 'subtree'.
319+
*
320+
* @throws When the scope is set to an unrecognized scope constant.
321+
*/
322+
get scopeName () {
323+
switch (this.#scope) {
324+
case search.SCOPE_BASE_OBJECT:
325+
return 'base'
326+
case search.SCOPE_ONE_LEVEL:
327+
return 'single'
328+
case search.SCOPE_SUBTREE:
329+
return 'subtree'
330+
}
331+
}
332+
321333
/**
322334
* The number of entries to limit search results to.
323335
*
@@ -424,7 +436,7 @@ class SearchRequest extends LdapMessage {
424436
*/
425437
_pojo (obj = {}) {
426438
obj.baseObject = this.baseObject.toString()
427-
obj.scope = this.scope
439+
obj.scope = this.scopeName
428440
obj.derefAliases = this.derefAliases
429441
obj.sizeLimit = this.sizeLimit
430442
obj.timeLimit = this.timeLimit

lib/messages/search-request.test.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,24 @@ tap.test('.filter', t => {
186186
tap.test('.scope', t => {
187187
t.test('sets/gets', async t => {
188188
const req = new SearchRequest()
189-
t.equal(req.scope, 'base')
189+
t.equal(req.scopeName, 'base')
190+
t.equal(req.scope, 0)
190191

191192
req.scope = SearchRequest.SCOPE_SINGLE
192-
t.equal(req.scope, 'single')
193+
t.equal(req.scopeName, 'single')
194+
t.equal(req.scope, 1)
193195

194196
req.scope = SearchRequest.SCOPE_SUBTREE
195-
t.equal(req.scope, 'subtree')
197+
t.equal(req.scopeName, 'subtree')
198+
t.equal(req.scope, 2)
196199

197200
req.scope = 'SUB'
198-
t.equal(req.scope, 'subtree')
201+
t.equal(req.scopeName, 'subtree')
202+
t.equal(req.scope, 2)
199203

200204
req.scope = 'base'
201-
t.equal(req.scope, 'base')
205+
t.equal(req.scopeName, 'base')
206+
t.equal(req.scope, 0)
202207
})
203208

204209
t.test('throws for invalid value', async t => {

0 commit comments

Comments
 (0)