@@ -31,6 +31,9 @@ exports.isMongooseDocumentArray = isMongooseDocumentArray.isMongooseDocumentArra
31
31
exports . registerMongooseArray = isMongooseArray . registerMongooseArray ;
32
32
exports . registerMongooseDocumentArray = isMongooseDocumentArray . registerMongooseDocumentArray ;
33
33
34
+ const oneSpaceRE = / \s / ;
35
+ const manySpaceRE = / \s + / ;
36
+
34
37
/**
35
38
* Produces a collection name from model `name`. By default, just returns
36
39
* the model name
@@ -572,8 +575,8 @@ exports.populate = function populate(path, select, model, match, options, subPop
572
575
function makeSingles ( arr ) {
573
576
const ret = [ ] ;
574
577
arr . forEach ( function ( obj ) {
575
- if ( / [ \s ] / . test ( obj . path ) ) {
576
- const paths = obj . path . split ( ' ' ) ;
578
+ if ( oneSpaceRE . test ( obj . path ) ) {
579
+ const paths = obj . path . split ( manySpaceRE ) ;
577
580
paths . forEach ( function ( p ) {
578
581
const copy = Object . assign ( { } , obj ) ;
579
582
copy . path = p ;
@@ -592,9 +595,9 @@ function _populateObj(obj) {
592
595
if ( Array . isArray ( obj . populate ) ) {
593
596
const ret = [ ] ;
594
597
obj . populate . forEach ( function ( obj ) {
595
- if ( / [ \s ] / . test ( obj . path ) ) {
598
+ if ( oneSpaceRE . test ( obj . path ) ) {
596
599
const copy = Object . assign ( { } , obj ) ;
597
- const paths = copy . path . split ( ' ' ) ;
600
+ const paths = copy . path . split ( manySpaceRE ) ;
598
601
paths . forEach ( function ( p ) {
599
602
copy . path = p ;
600
603
ret . push ( exports . populate ( copy ) [ 0 ] ) ;
@@ -609,7 +612,7 @@ function _populateObj(obj) {
609
612
}
610
613
611
614
const ret = [ ] ;
612
- const paths = obj . path . split ( ' ' ) ;
615
+ const paths = oneSpaceRE . test ( obj . path ) ? obj . path . split ( manySpaceRE ) : [ obj . path ] ;
613
616
if ( obj . options != null ) {
614
617
obj . options = clone ( obj . options ) ;
615
618
}
0 commit comments