Skip to content

Commit

Permalink
fix: Do not allow nested Parser functions. (#3155)
Browse files Browse the repository at this point in the history
Parser references must be strings.
  • Loading branch information
Jason3S authored Jun 29, 2022
1 parent f5b7f8e commit 8083c95
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/cspell-lib/api/api.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference types="node" />
import { Glob, CSpellSettingsWithSourceTrace, ReplaceMap, DictionaryInformation, DictionaryDefinitionPreferred, DictionaryDefinitionAugmented, DictionaryDefinitionCustom, TextOffset, TextDocumentOffset, PnPSettings as PnPSettings$1, ImportFileRef, CSpellUserSettings, MappedText, ParsedText, LocaleId, CSpellSettings } from '@cspell/cspell-types';
import { Glob, CSpellSettingsWithSourceTrace, ReplaceMap, DictionaryInformation, Parser, DictionaryDefinitionPreferred, DictionaryDefinitionAugmented, DictionaryDefinitionCustom, TextOffset, TextDocumentOffset, PnPSettings as PnPSettings$1, ImportFileRef, CSpellUserSettings, MappedText, ParsedText, LocaleId, CSpellSettings } from '@cspell/cspell-types';
export * from '@cspell/cspell-types';
import { CompoundWordsMethod, SuggestionResult, SuggestionCollector, WeightMap } from 'cspell-trie-lib';
export { CompoundWordsMethod, SuggestionCollector, SuggestionResult } from 'cspell-trie-lib';
Expand Down Expand Up @@ -227,6 +227,7 @@ interface CSpellSettingsInternal extends Omit<CSpellSettingsWithSourceTrace, 'di
dictionaryDefinitions?: DictionaryDefinitionInternal[];
}
interface CSpellSettingsInternalFinalized extends CSpellSettingsInternal {
parserFn: Parser | undefined;
finalized: true;
ignoreRegExpList: RegExp[];
includeRegExpList: RegExp[];
Expand Down
2 changes: 2 additions & 0 deletions packages/cspell-lib/src/Models/CSpellSettingsInternalDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
DictionaryDefinitionAugmented,
DictionaryDefinitionCustom,
DictionaryDefinitionPreferred,
Parser,
} from '@cspell/cspell-types';
import { WeightMap } from 'cspell-trie-lib';
import { OptionalOrUndefined } from '../util/types';
Expand All @@ -16,6 +17,7 @@ export interface CSpellSettingsInternal extends Omit<CSpellSettingsWithSourceTra
}

export interface CSpellSettingsInternalFinalized extends CSpellSettingsInternal {
parserFn: Parser | undefined;
finalized: true;
ignoreRegExpList: RegExp[];
includeRegExpList: RegExp[];
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-lib/src/Settings/CSpellSettingsServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ function _finalizeSettings(settings: CSpellSettingsI): CSpellSettingsInternalFin
finalized: true,
ignoreRegExpList: resolvePatterns(settings.ignoreRegExpList, settings.patterns),
includeRegExpList: resolvePatterns(settings.includeRegExpList, settings.patterns),
parser: resolveParser(settings),
parserFn: resolveParser(settings),
};

finalized.name = 'Finalized ' + (finalized.name || '');
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-lib/src/textValidation/docValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export class DocumentValidator {

private _parse(): Iterable<ParsedText> {
assert(this._preparations, ERROR_NOT_PREPARED);
const parser = this._preparations.finalSettings.parser;
const parser = this._preparations.finalSettings.parserFn;
if (typeof parser !== 'object') return this.defaultParser();
return parser.parse(this.document.text, this.document.uri.path).parsedTexts;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-types/src/CSpellSettingsDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ export interface ExperimentalBaseSettings {
* @experimental
* @version 6.2.0
*/
parser?: ParserName | Parser | undefined;
parser?: ParserName | undefined;
}

/**
Expand Down

0 comments on commit 8083c95

Please sign in to comment.