Skip to content

Commit

Permalink
fix(search): prevent lunr call stack size exceeded for huge file
Browse files Browse the repository at this point in the history
  • Loading branch information
vogloblinsky committed Dec 12, 2017
1 parent 68cefd4 commit f495cd8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/app/engines/search.engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { logger } from '../../logger';
import { Configuration } from '../configuration';
import { ConfigurationInterface } from '../interfaces/configuration.interface';
import { FileEngine } from './file.engine';
import { MAX_SIZE_FILE_SEARCH_INDEX } from '../../utils/defaults';

const lunr: any = require('lunr');
const cheerio: any = require('cheerio');
Expand Down Expand Up @@ -47,7 +48,8 @@ export class SearchEngine {
body: text
};

if (!this.documentsStore.hasOwnProperty(doc.url)) {
if (!this.documentsStore.hasOwnProperty(doc.url)
&& doc.body.length < MAX_SIZE_FILE_SEARCH_INDEX) {
this.documentsStore[doc.url] = doc;
this.getSearchIndex().add(doc);
}
Expand Down
7 changes: 7 additions & 0 deletions src/utils/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ export const COMPODOC_DEFAULTS = {
INTERNAL: 'internal'
}
};


/**
* Max length for the string of a file during Lunr search engine indexing.
* Prevent stack size exceeded
*/
export const MAX_SIZE_FILE_SEARCH_INDEX = 15000;
5 changes: 5 additions & 0 deletions test/src/cli/cli-generation-big-app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ describe('CLI simple generation - big app', () => {
expect(isIndexExists).to.be.true;
});

it('should have excluded big file for search index json', () => {
const searchIndexFile = read(`documentation/js/search/search_index.js`);
expect(searchIndexFile).to.not.contain('photo64_1');
});

it('should have generated extends information for todo class', () => {
const todoModelFile = read(`documentation/classes/Todo.html`);
expect(todoModelFile).to.contain('Extends');
Expand Down
49 changes: 49 additions & 0 deletions test/src/todomvc-ng2/src/app/shared/services/list-image.service.ts

Large diffs are not rendered by default.

0 comments on commit f495cd8

Please sign in to comment.