Skip to content

Commit f495cd8

Browse files
committed
fix(search): prevent lunr call stack size exceeded for huge file
fix #410 #378
1 parent 68cefd4 commit f495cd8

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

src/app/engines/search.engine.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { logger } from '../../logger';
55
import { Configuration } from '../configuration';
66
import { ConfigurationInterface } from '../interfaces/configuration.interface';
77
import { FileEngine } from './file.engine';
8+
import { MAX_SIZE_FILE_SEARCH_INDEX } from '../../utils/defaults';
89

910
const lunr: any = require('lunr');
1011
const cheerio: any = require('cheerio');
@@ -47,7 +48,8 @@ export class SearchEngine {
4748
body: text
4849
};
4950

50-
if (!this.documentsStore.hasOwnProperty(doc.url)) {
51+
if (!this.documentsStore.hasOwnProperty(doc.url)
52+
&& doc.body.length < MAX_SIZE_FILE_SEARCH_INDEX) {
5153
this.documentsStore[doc.url] = doc;
5254
this.getSearchIndex().add(doc);
5355
}

src/utils/defaults.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@ export const COMPODOC_DEFAULTS = {
2424
INTERNAL: 'internal'
2525
}
2626
};
27+
28+
29+
/**
30+
* Max length for the string of a file during Lunr search engine indexing.
31+
* Prevent stack size exceeded
32+
*/
33+
export const MAX_SIZE_FILE_SEARCH_INDEX = 15000;

test/src/cli/cli-generation-big-app.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ describe('CLI simple generation - big app', () => {
118118
expect(isIndexExists).to.be.true;
119119
});
120120

121+
it('should have excluded big file for search index json', () => {
122+
const searchIndexFile = read(`documentation/js/search/search_index.js`);
123+
expect(searchIndexFile).to.not.contain('photo64_1');
124+
});
125+
121126
it('should have generated extends information for todo class', () => {
122127
const todoModelFile = read(`documentation/classes/Todo.html`);
123128
expect(todoModelFile).to.contain('Extends');

test/src/todomvc-ng2/src/app/shared/services/list-image.service.ts

Lines changed: 49 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)