fix: changed the header argument processing from a forEach loop to a while loop to handle array modifications correctly, preventing index errors.
This commit is contained in:
parent
da1330d2aa
commit
026caedd3c
1 changed files with 14 additions and 10 deletions
|
@ -376,8 +376,9 @@ export async function findAvailablePort(preferredPort?: number): Promise<number>
|
||||||
export async function parseCommandLineArgs(args: string[], defaultPort: number, usage: string) {
|
export async function parseCommandLineArgs(args: string[], defaultPort: number, usage: string) {
|
||||||
// Process headers
|
// Process headers
|
||||||
const headers: Record<string, string> = {}
|
const headers: Record<string, string> = {}
|
||||||
args.forEach((arg, i) => {
|
let i = 0;
|
||||||
if (arg === '--header' && i < args.length - 1) {
|
while (i < args.length) {
|
||||||
|
if (args[i] === '--header' && i < args.length - 1) {
|
||||||
const value = args[i + 1]
|
const value = args[i + 1]
|
||||||
const match = value.match(/^([A-Za-z0-9_-]+):(.*)$/)
|
const match = value.match(/^([A-Za-z0-9_-]+):(.*)$/)
|
||||||
if (match) {
|
if (match) {
|
||||||
|
@ -386,8 +387,11 @@ export async function parseCommandLineArgs(args: string[], defaultPort: number,
|
||||||
log(`Warning: ignoring invalid header argument: ${value}`)
|
log(`Warning: ignoring invalid header argument: ${value}`)
|
||||||
}
|
}
|
||||||
args.splice(i, 2)
|
args.splice(i, 2)
|
||||||
|
// Do not increment i, as the array has shifted
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
i++
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
const serverUrl = args[0]
|
const serverUrl = args[0]
|
||||||
const specifiedPort = args[1] ? parseInt(args[1]) : undefined
|
const specifiedPort = args[1] ? parseInt(args[1]) : undefined
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue