Skip to content

Commit 57c2180

Browse files
committed
fix: invalid character in header
1 parent a99b27e commit 57c2180

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

packages/cli-server-api/src/__tests__/statusPageMiddleware.test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,23 @@ describe('statusPageMiddleware', () => {
2020
);
2121
expect(res.end).toHaveBeenCalledWith('packager-status:running');
2222
});
23+
24+
it('should set headers and end the response with invalid characters', () => {
25+
process.cwd = () => '/привіт/path';
26+
27+
const res: http.ServerResponse = {
28+
setHeader: jest.fn(),
29+
end: jest.fn(),
30+
} as any;
31+
32+
const mockReq: http.IncomingMessage = {} as any;
33+
statusPageMiddleware(mockReq, res);
34+
35+
// We're strictly checking response here, because React Native is strongly depending on this response. Changing the response might be a breaking change.
36+
expect(res.setHeader).toHaveBeenCalledWith(
37+
'X-React-Native-Project-Root',
38+
new URL(`file:///${process.cwd()}`).pathname.slice(1),
39+
);
40+
expect(res.end).toHaveBeenCalledWith('packager-status:running');
41+
});
2342
});

packages/cli-server-api/src/statusPageMiddleware.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export default function statusPageMiddleware(
1414
_req: http.IncomingMessage,
1515
res: http.ServerResponse,
1616
) {
17-
res.setHeader('X-React-Native-Project-Root', process.cwd());
17+
res.setHeader(
18+
'X-React-Native-Project-Root',
19+
new URL(`file:///${process.cwd()}`).pathname.slice(1),
20+
);
1821
res.end('packager-status:running');
1922
}

packages/cli-tools/src/getNextPort.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ const getNextPort = async (port: number, root: string): Promise<Result> => {
1919

2020
const isRunning = typeof result === 'object' && result.status === 'running';
2121

22-
if (isRunning && result.root === root) {
22+
if (
23+
isRunning &&
24+
result.root === new URL(`file:///${root}`).pathname.slice(1)
25+
) {
2326
// Found running bundler for this project, so we do not need to start packager!
2427
start = false;
2528
} else if (isRunning || result === 'unrecognized') {

0 commit comments

Comments
 (0)