Skip to content

Commit d3f7d77

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

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

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

+26-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@ import http from 'http';
22
import statusPageMiddleware from './../statusPageMiddleware';
33

44
describe('statusPageMiddleware', () => {
5-
it('should set headers and end the response', () => {
6-
process.cwd = () => '/mocked/path';
5+
let res: jest.Mocked<http.ServerResponse>;
6+
let mockReq: http.IncomingMessage;
77

8-
const res: http.ServerResponse = {
8+
beforeEach(() => {
9+
res = {
910
setHeader: jest.fn(),
1011
end: jest.fn(),
1112
} as any;
1213

13-
const mockReq: http.IncomingMessage = {} as any;
14+
mockReq = {} as any;
15+
});
16+
17+
afterEach(() => {
18+
jest.restoreAllMocks();
19+
});
20+
21+
it('should set headers and end the response', () => {
22+
jest.spyOn(process, 'cwd').mockReturnValue('/mocked/path');
23+
1424
statusPageMiddleware(mockReq, res);
1525

1626
// We're strictly checking response here, because React Native is strongly depending on this response. Changing the response might be a breaking change.
@@ -20,4 +30,16 @@ describe('statusPageMiddleware', () => {
2030
);
2131
expect(res.end).toHaveBeenCalledWith('packager-status:running');
2232
});
33+
34+
it('should set headers and end the response with decoded value', () => {
35+
jest.spyOn(process, 'cwd').mockReturnValue('/привіт/path');
36+
37+
statusPageMiddleware(mockReq, res);
38+
39+
expect(res.setHeader).toHaveBeenCalledWith(
40+
'X-React-Native-Project-Root',
41+
'/%D0%BF%D1%80%D0%B8%D0%B2%D1%96%D1%82/path',
42+
);
43+
expect(res.end).toHaveBeenCalledWith('packager-status:running');
44+
});
2345
});

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)