Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__proto__ disappears from the inverted index if you serialize an index that was loaded from a serialized JSON blob #378

Merged
merged 2 commits into from
Oct 16, 2018
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
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ lunr.Index.load = function (serializedIndex) {
var attrs = {},
fieldVectors = {},
serializedVectors = serializedIndex.fieldVectors,
invertedIndex = {},
invertedIndex = Object.create(null),
serializedInvertedIndex = serializedIndex.invertedIndex,
tokenSetBuilder = new lunr.TokenSet.Builder,
pipeline = lunr.Pipeline.load(serializedIndex.pipeline)
Expand Down
13 changes: 13 additions & 0 deletions test/serialization_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ suite('serialization', function () {
title: 'Scarlett helps Professor',
body: 'Miss Scarlett watered Professor Plumbs green plant while he was away from his office last week.',
wordCount: 16
},{
id: 'd',
title: 'All about JavaScript',
body: 'JavaScript objects have a special __proto__ property',
wordCount: 7
}]

this.idx = lunr(function () {
Expand All @@ -37,4 +42,12 @@ suite('serialization', function () {

assert.deepEqual(idxResults, serializedResults)
})

test('__proto__ double serialization', function () {
var doubleLoadedIdx = lunr.Index.load(JSON.parse(JSON.stringify(this.loadedIdx))),
idxResults = this.idx.search('__proto__'),
doubleSerializedResults = doubleLoadedIdx.search('__proto__')

assert.deepEqual(idxResults, doubleSerializedResults)
})
})