Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/regexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ export class BSONRegExp {
if (!(this instanceof BSONRegExp)) return new BSONRegExp(pattern, options);

this.pattern = pattern;
this.options = options ?? '';
// Execute
alphabetize(this.options);
this.options = alphabetize(options ?? '');

// Validate options
for (let i = 0; i < this.options.length; i++) {
Expand Down
5 changes: 5 additions & 0 deletions test/node/bson_corpus_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ describe('BSON Corpus', function () {

if (v.degenerate_bson) {
const dB = Buffer.from(v.degenerate_bson, 'hex');
// Degenerate BSON to JS equals canonical BSON in JS
expect(BSON.deserialize(cB, deserializeOptions)).to.deep.equal(
BSON.deserialize(dB, deserializeOptions)
);
// Dengenerate BSON roundtripped is transformed to canonical BSON
expect(cB).to.deep.equal(
BSON.serialize(BSON.deserialize(dB, deserializeOptions), serializeOptions)
);
Expand Down
7 changes: 7 additions & 0 deletions test/node/bson_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2164,6 +2164,13 @@ describe('BSON', function () {
done();
});

describe('BSONRegExp', () => {
it('Should alphabetize options', () => {
const b = new BSONRegExp('cba', 'mix');
expect(b.options).to.equal('imx');
});
});

/**
* @ignore
*/
Expand Down