Skip to content

Commit 2fe311d

Browse files
committed
Be more robust when parsing file url
1 parent 7dede72 commit 2fe311d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/host/app/components/ai-assistant/formatted-message.gts

+5-3
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,16 @@ function extractCodeData(preElementString: string) {
305305
// We need this url so that we know which file the code patch applies to.
306306
// We extract this url and remove it from the content.
307307
let fileUrl = null;
308-
if (content?.startsWith('// File url: ')) {
309-
let firstLine = content.split('\n')[0];
308+
309+
let trimmedContent = content?.trim();
310+
if (trimmedContent.trim().startsWith('// File url: ')) {
311+
let firstLine = trimmedContent.trim().split('\n')[0];
310312
let fileUrlRegex = /File url: (.*)/;
311313
let fileUrlMatch = firstLine.match(fileUrlRegex);
312314
if (fileUrlMatch) {
313315
fileUrl = fileUrlMatch[1];
314316
}
315-
content = content.slice(firstLine.length).trimStart();
317+
content = trimmedContent.slice(firstLine.length).trimStart();
316318
}
317319

318320
return {

0 commit comments

Comments
 (0)