MCPcopy Index your code
hub / github.com/react/react /

Function

packages/react-dom/src/__tests__/ReactDOMServerIntegrationElements-test.js:827–916  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

825 });
826
827 describe('carriage return and null character', () => {
828 // HTML parsing normalizes CR and CRLF to LF.
829 // It also ignores null character.
830 // https://www.w3.org/TR/html5/single-page.html#preprocessing-the-input-stream
831 // If we have a mismatch, it might be caused by that (and should not be reported).
832 // We won't be patching up in this case as that matches our past behavior.
833
834 itRenders(
835 'an element with one text child with special characters',
836 async render => {
837 const e = await render(<div>{'foo\rbar\r\nbaz\nqux\u0000'}</div>);
838 if (
839 render === serverRender ||
840 render === streamRender ||
841 render === clientRenderOnServerString
842 ) {
843 expect(e.childNodes.length).toBe(1);
844 // Everything becomes LF when parsed from server HTML or hydrated.
845 // Null character is ignored.
846 expectNode(e.childNodes[0], TEXT_NODE_TYPE, 'foo\nbar\nbaz\nqux');
847 } else {
848 expect(e.childNodes.length).toBe(1);
849 // Client rendering uses JS value with CR.
850 // Null character stays.
851
852 expectNode(
853 e.childNodes[0],
854 TEXT_NODE_TYPE,
855 'foo\rbar\r\nbaz\nqux\u0000',
856 );
857 }
858 },
859 );
860
861 itRenders(
862 'an element with two text children with special characters',
863 async render => {
864 const e = await render(
865 <div>
866 {'foo\rbar'}
867 {'\r\nbaz\nqux\u0000'}
868 </div>,
869 );
870 if (
871 render === serverRender ||
872 render === streamRender ||
873 render === clientRenderOnServerString
874 ) {
875 // We have three nodes because there is a comment between them.
876 expect(e.childNodes.length).toBe(3);
877 // Everything becomes LF when parsed from server HTML or hydrated.
878 // Null character is ignored.
879 expectNode(e.childNodes[0], TEXT_NODE_TYPE, 'foo\nbar');
880 expectNode(e.childNodes[2], TEXT_NODE_TYPE, '\nbaz\nqux');
881 } else if (render === clientRenderOnServerString) {
882 // We have three nodes because there is a comment between them.
883 expect(e.childNodes.length).toBe(3);
884 // Hydration uses JS value with CR and null character.

Callers

nothing calls this directly

Calls 5

itRendersFunction · 0.85
expectNodeFunction · 0.85
renderFunction · 0.70
ifFunction · 0.70
toBeMethod · 0.65

Tested by

no test coverage detected