Skip to content

Commit 063face

Browse files
committed
Escape the regex
1 parent c6b4423 commit 063face

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"dependencies": {
33
"markdown-magic": "^1.0.0",
44
"typescript": "latest",
5-
"glob": "^7.1.6"
5+
"glob": "^7.1.6",
6+
"escape-regex-string": "^1.0.6"
67
},
78
"scripts": {
89
"build": "md-magic --path '**/*.md'",

scripts/convertRelativeLinksToHardcoded.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const glob = require("glob")
1616
const {readFileSync, writeFileSync, existsSync} = require("fs")
1717
const {join} = require("path")
1818
const { execSync } = require("child_process");
19+
const escapeRegex = require("escape-regex-string");
1920

2021
if (!process.argv[2]) throw new Error("Did not include a glob for markdown files to change")
2122

@@ -45,7 +46,7 @@ files.forEach(file => {
4546
const originalFile = readFileSync(join(repoPath, file), "utf8")
4647
if (!originalFile) throw new Error(`Could not find a file at '${join(repoPath, file)}'`)
4748

48-
const line = getLineNo(originalFile, new RegExp(searchTerm))
49+
const line = getLineNo(originalFile, new RegExp(escapeRegex(searchTerm)))
4950
const lineRef = line && line[0] && line[0].number ? `#L${line[0].number}`: ""
5051
const replacement = `: https://github.com/microsoft/TypeScript/blob/${repoHead.trim()}/${file}${lineRef}`
5152
content = content.replace(original, replacement)

0 commit comments

Comments
 (0)