SSJS print() output new line


Matrix Version: v5.5.3.3

Has anyone got issues with SSJS where print() method output unwanted new line?

For example:

<div class="special-<script runat='server'>print('class');</script>">...</div>

Expected output will be:

<div class="special-class">...</div>

What I got is:

<div class="special-

(Bart Banda) #2

I can’t replicate this on, could potentially be the version of PHP/V8.js that is being used. Any idea of what that is on your instance?

(John gill) #3

I can replicate this behaviour in a site using Spidermonkey.

/var/www/matrix$ cat data/private/conf/  | 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-

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-

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()

<div class="special-<script runat='server'>putstr('cl');putstr('a');putstr('ss');</script>">...</div>
<div class="special-

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.


It is not a production system and it uses SpiderMonkey instead of V8. Sorry probably it should be in Support category. @Bart if you could change the category to General Discussion as I want to hear from others who has come across the issues.

It seems new line is also added when concatenating strings.