Skip to content

Commit 514a2e7

Browse files
committed
refactor(regexp): ensure options are alphabetically sorted
1 parent d60659d commit 514a2e7

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/bson/regexp.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
'use strict';
2+
3+
function alphabetize(str) {
4+
return str
5+
.split('')
6+
.sort()
7+
.join('');
8+
}
9+
210
/**
311
* A class representation of the BSON RegExp type.
412
*
@@ -11,7 +19,7 @@ function BSONRegExp(pattern, options) {
1119
// Execute
1220
this._bsontype = 'BSONRegExp';
1321
this.pattern = pattern || '';
14-
this.options = options || '';
22+
this.options = options ? alphabetize(options) : '';
1523

1624
// Validate options
1725
for (var i = 0; i < this.options.length; i++) {

0 commit comments

Comments
 (0)