Skip to content

Commit b01f47d

Browse files
committed
fix: use makePathRegexSafe with globSync
1 parent b1c7aac commit b01f47d

File tree

3 files changed

+49
-15
lines changed

3 files changed

+49
-15
lines changed

packages/cli/src/api/__snapshots__/catalog.test.ts.snap

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ exports[`Catalog POT Flow Should get translations from template if locale file n
1919
}
2020
`;
2121

22+
exports[`Catalog collect should extract files with special characters in the include path 1`] = `
23+
{
24+
Component D: {
25+
comments: [],
26+
context: undefined,
27+
message: undefined,
28+
origin: [
29+
[
30+
collect/[componentD]/index.js,
31+
1,
32+
],
33+
],
34+
placeholders: {},
35+
},
36+
}
37+
`;
38+
2239
exports[`Catalog collect should extract files with special characters when passed in options 1`] = `
2340
{
2441
Component C: {

packages/cli/src/api/catalog.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,21 @@ describe("Catalog", () => {
318318
expect(messages).toMatchSnapshot()
319319
})
320320

321+
it("should extract files with special characters in the include path", async () => {
322+
const catalog = new Catalog(
323+
{
324+
name: "messages",
325+
path: "locales/{locale}",
326+
include: [fixture("collect/[componentD]")],
327+
exclude: [],
328+
format,
329+
},
330+
mockConfig()
331+
)
332+
const messages = await catalog.collect()
333+
expect(messages).toMatchSnapshot()
334+
})
335+
321336
it("should throw an error when duplicate identifier with different defaults found", async () => {
322337
const catalog = new Catalog(
323338
{

packages/cli/src/api/catalog.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -264,22 +264,24 @@ export class Catalog {
264264
}
265265

266266
get sourcePaths() {
267-
const includeGlobs = this.include.map((includePath) => {
268-
const isDir = isDirectory(includePath)
269-
/**
270-
* glob library results from absolute patterns such as /foo/* are mounted onto the root setting using path.join.
271-
* On windows, this will by default result in /foo/* matching C:\foo\bar.txt.
272-
*/
273-
return isDir
274-
? normalize(
275-
path.resolve(
276-
process.cwd(),
277-
includePath === "/" ? "" : includePath,
278-
"**/*.*"
267+
const includeGlobs = this.include
268+
.map((includePath) => {
269+
const isDir = isDirectory(includePath)
270+
/**
271+
* glob library results from absolute patterns such as /foo/* are mounted onto the root setting using path.join.
272+
* On windows, this will by default result in /foo/* matching C:\foo\bar.txt.
273+
*/
274+
return isDir
275+
? normalize(
276+
path.resolve(
277+
process.cwd(),
278+
includePath === "/" ? "" : includePath,
279+
"**/*.*"
280+
)
279281
)
280-
)
281-
: includePath
282-
})
282+
: includePath
283+
})
284+
.map(makePathRegexSafe)
283285

284286
return globSync(includeGlobs, { ignore: this.exclude, mark: true })
285287
}

0 commit comments

Comments
 (0)