Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request handler: Remove everything after # from the URL #1126

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/php-wasm/node/src/test/php-request-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ describe.each(SupportedPHPVersions)(
expect(response.text).toEqual('true');
});

/**
* @see https://github.com/WordPress/wordpress-playground/issues/1120
*/
it('Should not propagate the # part of the URL to PHP', async () => {
php.writeFile('/index.php', `<?php echo $_SERVER['REQUEST_URI'];`);
const response = await handler.request({
url: '/index.php#foo',
});
expect(response.text).toEqual('/index.php');
});

it('Should allow mixing data and files when `body` is a JavaScript object', async () => {
php.writeFile(
'/index.php',
Expand Down
3 changes: 2 additions & 1 deletion packages/php-wasm/universal/src/lib/php-request-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ export class PHPRequestHandler implements RequestHandler {
request.url.startsWith('http://') ||
request.url.startsWith('https://');
const requestedUrl = new URL(
request.url,
// Remove the hash part of the URL as it's meant for the server.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's something wrong with this comment. It should either say "it's not meant for the server" or "it's meant only for the client."

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 06f27eb

request.url.split('#')[0],
isAbsolute ? undefined : DEFAULT_BASE_URL
);

Expand Down
Loading