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

fix: Patterns - only add u if no flags are given #1745

Merged
merged 2 commits into from
Sep 22, 2021
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 packages/cspell-lib/src/Settings/InDocSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('Validate InDocSettings', () => {
const matches = InDoc.getIgnoreRegExpFromDocument(sampleCode);
expect(matches).toEqual(['/\\/\\/\\/.*/', 'w\\w+berry', '/', '\\w+s{4}\\w+', '/faullts[/]?/ */']);
const regExpList = matches.map((s) => Text.stringToRegExp(s));
expect(regExpList).toEqual([/\/\/\/.*/gu, /w\w+berry/gimu, /\//gimu, /\w+s{4}\w+/gimu, /faullts[/]?\/ */gu]);
expect(regExpList).toEqual([/\/\/\/.*/g, /w\w+berry/gimu, /\//gimu, /\w+s{4}\w+/gimu, /faullts[/]?\/ */g]);
const ranges = TextRange.findMatchingRangesForPatterns(matches, sampleCode);
expect(ranges.length).toBe(39);
});
Expand Down
17 changes: 10 additions & 7 deletions packages/cspell-lib/src/util/text.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import { splitCamelCaseWord } from './text';

describe('Util Text', () => {
test.each`
pattern | expected
${''} | ${undefined}
${'a'} | ${/a/gimu}
${'/'} | ${/\//gimu}
${'/.*/'} | ${/.*/gu}
${'/.*/gi'} | ${/.*/giu}
${/abc/} | ${/abc/}
pattern | expected
${''} | ${undefined}
${'a'} | ${/a/gimu}
${'/'} | ${/\//gimu}
${'/.*/'} | ${/.*/g}
${'/.*/m'} | ${/.*/gm}
${'/.*/gi'} | ${/.*/gi}
${'/.*/giu'} | ${/.*/giu}
${/abc/} | ${/abc/}
${/abc/gu} | ${/abc/gu}
`('tests build regexp from string', ({ pattern, expected }) => {
expect(Text.stringToRegExp(pattern)).toEqual(expected);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-lib/src/util/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function offsetMap(offset: number) {
return <T extends OffsetMap>(xo: T) => ({ ...xo, offset: xo.offset + offset } as T);
}

export function stringToRegExp(pattern: string | RegExp, defaultFlags = 'gimu', forceFlags = 'gu'): RegExp | undefined {
export function stringToRegExp(pattern: string | RegExp, defaultFlags = 'gimu', forceFlags = 'g'): RegExp | undefined {
if (pattern instanceof RegExp) {
return pattern;
}
Expand Down