jcu-eresearch / matrix-helpers

100% Unguessable™. Public bug tracker, pages, designs and helpers that make life in Squiz Matrix easier. The metaphorical red pill.
https://jcu-eresearch.github.io/matrix-helpers/
GNU Affero General Public License v3.0
3 stars 0 forks source link

Server-side JavaScript breaks on evaluating src tags in bodycopy-only views #53

Open davidjb opened 7 years ago

davidjb commented 7 years ago

A direct bodycopy div rendering via https://www.example.com/site/_nocache?a=12345 (where the Preview -> In New Window sends you) or via ?SQ_ASSET_CONTENTS=12345 evaluates SSJS but has issues when attempting to include SSJS via src. This example is just printing:

<script runat="server" src="./?a=123"></script>
<script runat="server">print('Run at server')</script>

and the browser receives output of:

  <script runat="server" src="../designs/[design-name]/[ssjs-filename].js"></script>

so the server script tag goes to the client instead of being processed, and the following print statement doesn't (appear) to succeed.

If I change the example to

  <script runat="server">print('Run before src include')</script>
  <script runat="server" src="./?a=123"></script>
  <script runat="server">print('Run after src include')</script>

I end up with the following output:

  Run before src include
  <script runat="server" src="../designs/[design-name]/[ssjs-filename].js"></script>

so the SSJS runs before it hits the src tag but not after. Finally, the result that makes me think this is related to the SSJS concatenation issue from earlier. This is the code:

  <script runat="server">print('Run before src include')</script>
  <script runat="server" src="./?a=123"></script>
  <script runat="server">print('Run after src include')</script>

  <h1>After the SSJS blocks</h1>
  <script runat="server">print('Run after h1 tag')</script>

which produces:

  Run before src include
  <script runat="server" src="../designs/[design-name]/[ssjs-filename].js"></script>
  Run after h1 tag

  <h1>After the SSJS blocks</h1>

So you end up with messed up output -- the later h1 print ends up too early and the server script block still gets sent to the client.

Content of the src included SSJS file doesn't appear to matter; pointing the src at an empty file yields the same result as having something in it.

davidjb commented 7 years ago

Reported at https://squizmap.squiz.net/matrix/10584. This breaks our preview windows until we can find a workaround. Grrr.

davidjb commented 7 years ago

Workaround:

  <script runat="server" id="underscore.js">
    %globals_asset_file_contents:12345%
  </script>

Solved for now.