Skip to content

fix: use makePathRegexSafe with globSync #2242

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

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
17 changes: 17 additions & 0 deletions packages/cli/src/api/__snapshots__/catalog.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ exports[`Catalog POT Flow Should get translations from template if locale file n
}
`;

exports[`Catalog collect should extract files with special characters in the include path 1`] = `
{
Component D: {
comments: [],
context: undefined,
message: undefined,
origin: [
[
collect/[componentD]/index.js,
1,
],
],
placeholders: {},
},
}
`;

exports[`Catalog collect should extract files with special characters when passed in options 1`] = `
{
Component C: {
Expand Down
15 changes: 15 additions & 0 deletions packages/cli/src/api/catalog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,21 @@ describe("Catalog", () => {
expect(messages).toMatchSnapshot()
})

it("should extract files with special characters in the include path", async () => {
const catalog = new Catalog(
{
name: "messages",
path: "locales/{locale}",
include: [fixture("collect/[componentD]")],
exclude: [],
format,
},
mockConfig()
)
const messages = await catalog.collect()
expect(messages).toMatchSnapshot()
})

it("should throw an error when duplicate identifier with different defaults found", async () => {
const catalog = new Catalog(
{
Expand Down
32 changes: 17 additions & 15 deletions packages/cli/src/api/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,22 +264,24 @@ export class Catalog {
}

get sourcePaths() {
const includeGlobs = this.include.map((includePath) => {
const isDir = isDirectory(includePath)
/**
* glob library results from absolute patterns such as /foo/* are mounted onto the root setting using path.join.
* On windows, this will by default result in /foo/* matching C:\foo\bar.txt.
*/
return isDir
? normalize(
path.resolve(
process.cwd(),
includePath === "/" ? "" : includePath,
"**/*.*"
const includeGlobs = this.include
.map((includePath) => {
const isDir = isDirectory(includePath)
/**
* glob library results from absolute patterns such as /foo/* are mounted onto the root setting using path.join.
* On windows, this will by default result in /foo/* matching C:\foo\bar.txt.
*/
return isDir
? normalize(
path.resolve(
process.cwd(),
includePath === "/" ? "" : includePath,
"**/*.*"
)
)
)
: includePath
})
: includePath
})
.map(makePathRegexSafe)

return globSync(includeGlobs, { ignore: this.exclude, mark: true })
}
Expand Down