Skip to content

Commit bc89221

Browse files
committed
Fix for "Incomplete string escaping or encoding"
Atttempts fix the "Incomplete string escaping or encoding" code scanning alert generated for the `extractors/cds/tools/src/cdsCompiler.ts` file. Re-adds shell-quote sanitization logic that was lost during the translation from "one big JavaScript script" to a modular solution implemented primarily in TypeScript.
1 parent 13e4aa4 commit bc89221

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

extractors/cds/tools/src/cdsCompiler.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { execFileSync, spawnSync, SpawnSyncReturns } from 'child_process';
22
import { resolve } from 'path';
33

4+
import * as shellQuote from 'shell-quote';
5+
46
import { fileExists, dirExists, recursivelyRenameJsonFiles } from './filesystem';
57

68
/**
@@ -115,8 +117,8 @@ export function addCompilationDiagnostic(
115117
codeqlExePath: string,
116118
): boolean {
117119
try {
118-
// Escape the error message for safe command line usage
119-
const escapedErrorMessage = errorMessage.replace(/"/g, '\\"').replace(/\n/g, '\\n');
120+
// Use shell-quote to safely escape the error message
121+
const escapedErrorMessage = shellQuote.quote([errorMessage]);
120122

121123
execFileSync(codeqlExePath, [
122124
'database',
@@ -126,7 +128,7 @@ export function addCompilationDiagnostic(
126128
'--source-id=cds/compilation-failure',
127129
'--source-name=Failure to compile one or more SAP CAP CDS files',
128130
'--severity=error',
129-
`--markdown-message=${escapedErrorMessage}`,
131+
`--markdown-message=${escapedErrorMessage.slice(1, -1)}`, // Remove the added quotes from shell-quote
130132
`--file-path=${resolve(cdsFilePath)}`,
131133
'--',
132134
`${process.env.CODEQL_EXTRACTOR_CDS_WIP_DATABASE ?? ''}`,

0 commit comments

Comments
 (0)