File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -89,3 +89,33 @@ function createMiddlewareResponse($response): SymfonyResponse
8989 'with head and body tags ' => '<html><head><title>Test</title></head><body></body></html> ' ,
9090 'without head/body tags ' => '<html>Test</html> ' ,
9191]);
92+
93+ it ('does not inject script inside javascript template literals ' , function () {
94+ $ html = '<html><head><title>Test</title></head><body><script>
95+ let html = `
96+ <html>
97+ <head><title>Dynamic Title</title></head>
98+ <body>
99+ <h1>Hello World</h1>
100+ </body>
101+ </html>
102+ `;
103+ document.body.innerHTML = html;
104+ </script></body></html> ' ;
105+
106+ $ response = new Response ($ html );
107+ $ response ->headers ->set ('content-type ' , 'text/html ' );
108+
109+ $ result = createMiddlewareResponse ($ response );
110+ $ content = $ result ->getContent ();
111+
112+ expect ($ content )->toContain ('<script id="browser-logger-active"> ' )
113+ ->and ($ content )->toContain ('let html = ` ' )
114+ ->and ($ content )->toContain ('document.body.innerHTML = html; ' );
115+
116+ $ originalScriptStart = strpos ($ content , 'let html = ` ' );
117+ $ originalScriptEnd = strpos ($ content , 'document.body.innerHTML = html; ' ) + strlen ('document.body.innerHTML = html; ' );
118+ $ originalScript = substr ($ content , $ originalScriptStart , $ originalScriptEnd - $ originalScriptStart );
119+
120+ expect ($ originalScript )->not ->toContain ('browser-logger-active ' );
121+ });
You can’t perform that action at this time.
0 commit comments