Skip to content

Commit b104159

Browse files
authored
QUERY_STRING should default to empty string (#139)
1 parent d6093e2 commit b104159

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

packages/php-wasm/node/src/test/php.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,17 @@ bar1
18331833
);
18341834
expect($_SERVER).toHaveProperty('HTTP_X_IS_AJAX', 'true');
18351835
expect($_SERVER).toHaveProperty('SERVER_PORT', '1235');
1836+
expect($_SERVER).toHaveProperty('QUERY_STRING', 'a=b');
1837+
});
1838+
1839+
it('Should have an empty QUERY_STRING when the URI has no query string', async () => {
1840+
const response = await php.run({
1841+
code: `<?php echo json_encode($_SERVER);`,
1842+
relativeUri: '/test.php',
1843+
});
1844+
const bodyText = new TextDecoder().decode(response.bytes);
1845+
const $_SERVER = JSON.parse(bodyText);
1846+
expect($_SERVER).toHaveProperty('QUERY_STRING', '');
18361847
});
18371848
});
18381849

packages/php-wasm/universal/src/lib/php.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,16 @@ export class PHP implements Disposable {
577577
[STRING],
578578
[uri]
579579
);
580+
let queryString = '';
580581
if (uri.includes('?')) {
581-
const queryString = uri.substring(uri.indexOf('?') + 1);
582-
this[__private__dont__use].ccall(
583-
'wasm_set_query_string',
584-
null,
585-
[STRING],
586-
[queryString]
587-
);
582+
queryString = uri.substring(uri.indexOf('?') + 1);
588583
}
584+
this[__private__dont__use].ccall(
585+
'wasm_set_query_string',
586+
null,
587+
[STRING],
588+
[queryString]
589+
);
589590
}
590591

591592
#setRequestHost(host: string) {

0 commit comments

Comments
 (0)