Skip to content

Commit a33a6da

Browse files
committed
fix(shared): ignore unfinished quoted Git config continuations
1 parent 8b44f42 commit a33a6da

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

‎packages/shared/src/git.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ describe("isBareGitConfig", () => {
7171

7272
expect(isBareGitConfig(config)).toBe(true);
7373
expect(isBareGitConfig("[core]\nbare = tr\\\nue\\")).toBe(true);
74+
expect(isBareGitConfig('[core]\nbare = "true\\')).toBe(false);
75+
expect(isBareGitConfig('[core]\nbare = "true\\\n')).toBe(false);
7476
});
7577
});
7678

‎packages/shared/src/git.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function* gitConfigLines(configText: string) {
175175
let quoted = false;
176176
for (const line of configText.split(/\r?\n/)) {
177177
let continued = false;
178-
if (line.endsWith("\\")) {
178+
if (line.endsWith("\\") || pending.length > 0) {
179179
for (const [token] of line.matchAll(/\\[\s\S]?|["#;]/g)) {
180180
if (token === '"') quoted = !quoted;
181181
else if (!quoted && (token === "#" || token === ";")) break;
@@ -186,11 +186,11 @@ function* gitConfigLines(configText: string) {
186186
pending += line.slice(0, -1);
187187
continue;
188188
}
189-
yield pending + line;
189+
if (!quoted) yield pending + line;
190190
pending = "";
191191
quoted = false;
192192
}
193-
if (pending.length > 0) yield pending;
193+
if (pending.length > 0 && !quoted) yield pending;
194194
}
195195

196196
function parseGitConfigValue(raw: string): string {

0 commit comments

Comments
 (0)