Skip to content
TypeScript

fix(shared): ignore unfinished quoted Git config continuations (#30743)

Harjot Singh2b0f08b5246f
diff --git a/packages/shared/src/git.test.ts b/packages/shared/src/git.test.ts
index a21a52cb70e..07ea0a5652d 100644
--- a/packages/shared/src/git.test.ts
+++ b/packages/shared/src/git.test.ts
@@ -112,6 +112,8 @@ describe("isBareGitConfig", () => {
expect(isBareGitConfig(config)).toBe(true);
expect(isBareGitConfig("[core]\nbare = tr\\\nue\\")).toBe(true);
+ expect(isBareGitConfig('[core]\nbare = "true\\')).toBe(false);
+ expect(isBareGitConfig('[core]\nbare = "true\\\n')).toBe(false);
});
});
diff --git a/packages/shared/src/git.ts b/packages/shared/src/git.ts
index 9f7c6c3227e..e03bd125a4a 100644
--- a/packages/shared/src/git.ts
+++ b/packages/shared/src/git.ts
@@ -175,7 +175,7 @@ function* gitConfigLines(configText: string) {
let quoted = false;
for (const line of configText.split(/\r?\n/)) {
let continued = false;
- if (line.endsWith("\\")) {
+ if (line.endsWith("\\") || pending.length > 0) {
for (const [token] of line.matchAll(/\\[\s\S]?|["#;]/g)) {
if (token === '"') quoted = !quoted;
else if (!quoted && (token === "#" || token === ";")) break;
@@ -186,11 +186,11 @@ function* gitConfigLines(configText: string) {
pending += line.slice(0, -1);
continue;
}
- yield pending + line;
+ if (!quoted) yield pending + line;
pending = "";
quoted = false;
}
- if (pending.length > 0) yield pending;
+ if (pending.length > 0 && !quoted) yield pending;
}
function parseGitConfigValue(raw: string): string {