fix(project-detect): retain multiline continuations and array boundaries

This commit is contained in:
Afloat committed 2026-11-17 11:23:16 +08:00
1 parent f9f3ed5ccf
commit a796cab879
2 files changed
+27 -2

No files matched your search

+18 -2
View File
@@ -198,9 +198,21 @@ function readTomlQuotedValue(content, start) {
// TOML trims a newline immediately after a multiline opening delimiter.
if (multiline && content.startsWith('\r\n', index)) index += 2;
else if (multiline && content[index] === '\n') index++;
const valueStart = index;
let valueStart = index;
const parts = [];
const continuation = /\\[ \t]*\r?\n[ \t\r\n]*/y;
while (index < content.length) {
if (quote === '"' && content[index] === '\\') {
if (multiline) {
continuation.lastIndex = index;
const match = continuation.exec(content);
if (match) {
parts.push(content.slice(valueStart, index));
index = continuation.lastIndex;
valueStart = index;
continue;
}
}
index += 2;
continue;
}
@@ -210,7 +222,8 @@ function readTomlQuotedValue(content, start) {
if (multiline) {
while (end < index + 5 && content[end] === quote) end++;
}
return { value: content.slice(valueStart, end - delimiter.length), end };
parts.push(content.slice(valueStart, end - delimiter.length));
return { value: parts.join(''), end };
}
if (!multiline && (content[index] === '\n' || content[index] === '\r')) return null;
index++;
@@ -253,6 +266,9 @@ function readTomlDependencyArray(content) {
continue;
}
}
// Dependency values are strings; an unquoted opening bracket here can be
// a later table header while the dependency array is still unfinished.
if (values !== null && character === '[') return [];
if (values !== null && character === ']') return values;
index++;
}
@@ -47,6 +47,9 @@ test('keeps escaped quotes in environment markers inside one requirement',
test('does not parse an unterminated dependency array',
'[project]\ndependencies = ["fastapi[standard]"\n',
[], []);
test('does not use a later table header to close an unfinished dependency array',
'[project]\ndependencies = ["fastapi",\n[tool.demo]\n',
[], []);
test('retains dependencies in a project inline table',
'project = { name = "demo", version = "1.0", dependencies = ["fastapi[standard]", "flask"] }\n',
['fastapi', 'flask'], ['fastapi', 'flask']);
@@ -65,6 +68,12 @@ test('keeps single quotes inside multiline literal descriptions',
test('trims the opening newline of multiline quoted requirements',
"[project]\ndependencies = ['''\nfastapi''', \"\"\"\r\nflask\"\"\"]\n",
['fastapi', 'flask'], ['fastapi', 'flask']);
test('joins escaped newlines inside multiline basic requirements',
'[project]\ndependencies = ["""fast\\\n api""", """fl\\ \t\r\n\n ask"""]\n',
['fastapi', 'flask'], ['fastapi', 'flask']);
test('leaves multiline literal backslashes unchanged',
"[project]\ndependencies = ['''fast\\\napi''']\n",
['fast\\'], []);
test('allows one or two quote characters before a multiline closing delimiter',
'[project]\ndescription = """quoted"""""\ndependencies = ["flask"]\n',
['flask'], ['flask']);