Skip to content

Commit c09a054

Browse files
committed
Fix posting newlines in comments
1 parent eb35c9d commit c09a054

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

cli/bin/postgres-ai.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,24 @@ mon
11671167
console.log("");
11681168
});
11691169

1170+
/**
1171+
* Interpret escape sequences in a string (e.g., \n -> newline)
1172+
* Note: In regex, to match literal backslash-n, we need \\n in the pattern
1173+
* which requires \\\\n in the JavaScript string literal
1174+
*/
1175+
function interpretEscapes(str: string): string {
1176+
// First handle double backslashes by temporarily replacing them
1177+
// Then handle other escapes, then restore double backslashes as single
1178+
return str
1179+
.replace(/\\\\/g, '\x00') // Temporarily mark double backslashes
1180+
.replace(/\\n/g, '\n') // Match literal backslash-n (\\\\n in JS string -> \\n in regex -> matches \n)
1181+
.replace(/\\t/g, '\t')
1182+
.replace(/\\r/g, '\r')
1183+
.replace(/\\"/g, '"')
1184+
.replace(/\\'/g, "'")
1185+
.replace(/\x00/g, '\\'); // Restore double backslashes as single
1186+
}
1187+
11701188
// Issues management
11711189
const issues = program.command("issues").description("issues management");
11721190

@@ -1239,6 +1257,17 @@ issues
12391257
.option("--debug", "enable debug output")
12401258
.action(async (issueId: string, content: string, opts: { parent?: string; debug?: boolean }) => {
12411259
try {
1260+
// Interpret escape sequences in content (e.g., \n -> newline)
1261+
if (opts.debug) {
1262+
// eslint-disable-next-line no-console
1263+
console.log(`Debug: Original content: ${JSON.stringify(content)}`);
1264+
}
1265+
content = interpretEscapes(content);
1266+
if (opts.debug) {
1267+
// eslint-disable-next-line no-console
1268+
console.log(`Debug: Interpreted content: ${JSON.stringify(content)}`);
1269+
}
1270+
12421271
const rootOpts = program.opts<CliOptions>();
12431272
const cfg = config.readConfig();
12441273
const { apiKey } = getConfig(rootOpts);

0 commit comments

Comments
 (0)