Skip to content

Commit b63effb

Browse files
committed
fix: handle backslash and double-quote in a single pass in toPhpIniPath (CodeQL #70)
Replace the two chained .replace() calls with a single-pass regex that handles both \ and " in one substitution. This eliminates any ordering ambiguity between the two transforms and resolves the CodeQL js/incomplete-sanitization alert: there is now no intermediate state where a newly introduced backslash could interact with a not-yet-processed double-quote character.
1 parent e6e9667 commit b63effb

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

‎apps/cli/lib/native-php/config.ts‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,13 @@ function getExtensionDir( phpVersion: NativePhpSupportedVersion ): string {
136136
}
137137

138138
// PHP's INI parser on Windows accepts forward slashes inside quoted values
139-
// and is fussy about backslashes (which also act as escape characters). Use
140-
// forward slashes everywhere and escape stray double quotes.
141-
//
142-
// Backslashes are replaced with forward slashes first so that no backslashes
143-
// remain by the time we escape double-quote characters. This ordering is
144-
// intentional: converting \ → / before escaping " means a sequence like \"
145-
// in the original path cannot corrupt the resulting INI value.
139+
// and is fussy about backslashes (which also act as escape characters).
140+
// Handle both characters in a single pass: backslashes become forward slashes,
141+
// and double-quotes are backslash-escaped. Using one replace() call avoids any
142+
// ordering ambiguity — there is no intermediate state where a newly introduced
143+
// backslash could interact with a not-yet-processed double-quote.
146144
function toPhpIniPath( filePath: string ): string {
147-
const forwardSlashed = filePath.replace( /\\/g, '/' );
148-
return forwardSlashed.replace( /"/g, '\\"' );
145+
return filePath.replace( /[\\"]/g, ( char ) => ( char === '\\' ? '/' : '\\"' ) );
149146
}
150147

151148
function getNativePhpIniPath( phpVersion: NativePhpSupportedVersion ): string {

0 commit comments

Comments
 (0)