Skip to content

Commit

Permalink
fix special chars
Browse files Browse the repository at this point in the history
  • Loading branch information
Bajdzis committed Feb 20, 2021
1 parent 7cd077e commit 60f807f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/strings/splitStringWithSplitter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

function escapeRegExp(text: string) {
export function escapeRegExp(text: string) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}

Expand Down
10 changes: 5 additions & 5 deletions src/variableTemplate/createVariableTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AwesomeTreeError } from '../errors/AwesomeTreeError';
import { PathInfo } from '../fileInfo/getInfoAboutPath';
import { changeToUnixSlashes } from '../strings/changeToUnixSlashes';
import { AwesomeTreeError } from '../errors/AwesomeTreeError';
import { getTextCaseSingleWord, getTextCase } from '../textCase/getTextCase';

import { escapeRegExp } from '../strings/splitStringWithSplitter';
import { getTextCase, getTextCaseSingleWord } from '../textCase/getTextCase';

export function createVariableTemplate(search:string, information: PathInfo[], maxIterate: number = 500) {
const variables: {
Expand All @@ -27,13 +27,13 @@ export function createVariableTemplate(search:string, information: PathInfo[], m

words.forEach((variableName) => {
const [type, index0, index1, index2] = variables[variableName];
const regExp = new RegExp(`(?<=^([^\\$\\{]|\\$\\{[^"]*\\})*)(?<varName>${variableName})`,'i');
const regExp = new RegExp(`(?<=^([^\\$\\{]|\\$\\{[^"]*\\})*)(?<varName>${escapeRegExp(variableName)})`,'i');
let regExpResult: RegExpExecArray|null = null;

while ((regExpResult = regExp.exec(result)) !== null) {
const word = regExpResult[0];
const textCase = type === 'singleWord' ? getTextCaseSingleWord(word) : getTextCase(word);
const allCurrentWord = new RegExp(`(?<=^([^\\$\{]|\\$\\{[^"]*\\})*)(?<varName>${word})`, 'g');
const allCurrentWord = new RegExp(`(?<=^([^\\$\{]|\\$\\{[^"]*\\})*)(?<varName>${escapeRegExp(word)})`, 'g');
if (textCase === 'other') {
result = result.replace( allCurrentWord, `\${:${word}:}` );
} else {
Expand Down

0 comments on commit 60f807f

Please sign in to comment.