I can replicate this behaviour in a 5.5.1.0 site using Spidermonkey.
/var/www/matrix$ cat data/private/conf/tools.inc | grep JS
define('SQ_TOOL_JS_PATH', '/usr/bin/js52');
define('SQ_TOOL_JS_TIMEOUT', '30');
/var/www/matrix$ dpkg -l | grep libmozjs
ii libmozjs-52-0:amd64 52.9.1-0ubuntu0.18.04.1 amd64 SpiderMonkey JavaScript library
ii libmozjs-52-dev 52.9.1-0ubuntu0.18.04.1 amd64 SpiderMonkey JavaScript library - development headers
Surprisingly, it’s not just caused by the script block. If I split that ‘class’ example over two print statements I get a third newline:
<div class="special-<script runat='server'>print('cl');print('ass');</script>">...</div>
<div class="special-
cl
ass
">...</div>
Also, if I have an SSJS block with no print statements, I get a single newline
<div class="special-<script runat='server'></script>">,,,</div>
<div class="special-
">,,,</div>
So the behaviour appears to be “one newline incurred by executing the SSJS, plus one extra newline per print()
call”.
You can fix part of it by replacing print()
with putstr()
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Shell_global_objects
<div class="special-<script runat='server'>putstr('cl');putstr('a');putstr('ss');</script>">...</div>
<div class="special-
class">...</div>
Which isn’t particularly helpful (especially since putstr
is Spidermonkey specific). If your site is Squiz hosted I don’t imagine it would be using Spidermonkey anyway, the execution overheads are significant. If you want to check which JS engine it’s using, create a REST resource and see if it tells you you can’t use V8js.
I’m not able to replicate this behaviour with V8js.