Automattic / Automattic/mongoose
Allow populating paths with spaces
- Dominant language
- JavaScript
- Stars
- 27.5k
- Forks
- 4k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 32
Description
### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
The following test fails, there's no way to populate the 'original author' path that I can see:
```javascript
it('allows populating path with space in name (gh-13951)', async function() {
const BlogPost = db.model('BlogPost', new Schema({
title: String,
'original author': { type: ObjectId, ref: 'User' },
author: { type: ObjectId, ref: 'User' }
}));
const User = db.model('User', new Schema({ name: String }));
const fans = await User.create([{ name: 'Fan 1' }]);
const posts = [
{ title: 'Test 1', author: fans[0]._id, 'original author': fans[0]._id }
];
await BlogPost.create(posts);
const blogPost = await BlogPost.
findOne({ title: 'Test 1' }).
populate({ path: 'original author' });
assert.equal(blogPost['original author'].name, 'Fan 1');
assert.equal(blogPost.title, 'Test 1');
});
```
Worth finding a way to support this behavior without breaking existing logic that relies on whitespace to separate multiple paths.
Contributor guide
Research direction
Start with the provided JavaScript reproduction for gh-13951 and run it to confirm the failing populate behavior. Trace how populate({ path: 'original author' }) handles whitespace-separated paths, then verify that paths containing spaces populate correctly without breaking multiple-path parsing; the reproduction's assertions define done.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, mongodb
- Domain
- backend, databases
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 63/100