Skip to content

Commit

Permalink
fix(NODE-3282): BSONRegExp options not alphabetized (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
andymina authored Jun 8, 2021
1 parent 53cf5c6 commit 18c3512
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
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

0 comments on commit 18c3512

Please sign in to comment.