From 002cce0874201fd6fc05a69532caeb1db0b8aeb0 Mon Sep 17 00:00:00 2001 From: floweeb Date: Sun, 22 Dec 2024 18:26:00 +0300 Subject: [PATCH 1/2] feat: changing hashing from MD5 to SHA256 --- packages/react-server/src/ReactServerStreamConfigNode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-server/src/ReactServerStreamConfigNode.js b/packages/react-server/src/ReactServerStreamConfigNode.js index fe03332618140..0e5e7bf17004f 100644 --- a/packages/react-server/src/ReactServerStreamConfigNode.js +++ b/packages/react-server/src/ReactServerStreamConfigNode.js @@ -232,7 +232,7 @@ export function closeWithError(destination: Destination, error: mixed): void { } export function createFastHash(input: string): string | number { - const hash = createHash('md5'); + const hash = createHash('sha256'); hash.update(input); return hash.digest('hex'); } From bbd3194bba6580e12f56376b8bd29965d8644b8f Mon Sep 17 00:00:00 2001 From: floweeb Date: Wed, 25 Dec 2024 17:54:41 +0300 Subject: [PATCH 2/2] [tests] Added tests for the createFastHash function that uses sha256 now. Merry christmas :) --- packages/react-server/src/__tests__/ReactServer-test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/react-server/src/__tests__/ReactServer-test.js b/packages/react-server/src/__tests__/ReactServer-test.js index d827e82de0cac..cc32b5ca90b97 100644 --- a/packages/react-server/src/__tests__/ReactServer-test.js +++ b/packages/react-server/src/__tests__/ReactServer-test.js @@ -12,6 +12,7 @@ let React; let ReactNoopServer; +let sha256; describe('ReactServer', () => { beforeEach(() => { @@ -19,6 +20,7 @@ describe('ReactServer', () => { React = require('react'); ReactNoopServer = require('react-noop-renderer/server'); + sha256 = require('../ReactServerStreamConfigNode.js') }); function div(...children) { @@ -32,4 +34,10 @@ describe('ReactServer', () => { const result = ReactNoopServer.render(
hello world
); expect(result.root).toEqual(div('hello world')); }); + + it('correctly computes sha256', () =>{ + const expectedOutput = 'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'; + const hash = sha256.createFastHash('hello world'); + expect(hash).toBe(expectedOutput); + }); });