-
Notifications
You must be signed in to change notification settings - Fork 21
Description
When Apache parses SSI statements, it treats = and == as equivalent in conditional expressions, and if a variable is on the left side of the operator, the variable's value remains unchanged after the statement is evaluated.
For example, if variableName is set to 'someValue', then <!--#if expr="$variableName = 'anotherValue'"--> and <!--#if expr="$variableName == 'anotherValue''"--> will both evaluate as false, and variableName's value will still be someValue.
In node-ssi, however, using = with a variable in an #if statement causes the variable's value to change. The workaround is to use == instead, but ideally that shouldn't be necessary.
Test Code
I created a test here: https://runkit.com/lordpachelbel/runkit-npm-node-ssi — You can click the tiny arrow to the left of the console output to see it rendered as HTML.
The unminified version of the HTML string in that test is this:
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8" />
<title>SSI test page</title>
</head>
<body>
<h1>SSI test page</h1>
<p>Initial <code>#set</code> happens here.</p>
<!--#set var="loginStatus" value="on"-->
<p><code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<h2>Using <code>==</code></h2>
<p><code>#if expr="$loginStatus == 1"</code> :<br />
<!--#if expr="$loginStatus == 1"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<p><code>#if expr="$loginStatus == '1'"</code> :<br />
<!--#if expr="$loginStatus == '1'"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<p><code>#if expr="$loginStatus == 'on'"</code> :<br />
<!--#if expr="$loginStatus == 'on'"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<p><code>#if expr="$loginStatus == ''"</code> :<br />
<!--#if expr="$loginStatus == ''"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<p><code>#if expr="$loginStatus == 'anything'"</code> :<br />
<!--#if expr="$loginStatus == 'anything'"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<h2>Using <code>=</code></h2>
<p><code>#if expr="$loginStatus = 1"</code> :<br />
<!--#if expr="$loginStatus = 1"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<p><code>#if expr="$loginStatus = '1'"</code> :<br />
<!--#if expr="$loginStatus = '1'"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<p><code>#if expr="$loginStatus = 'on'"</code> :<br />
<!--#if expr="$loginStatus = 'on'"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<p><code>#if expr="$loginStatus = ''"</code> :<br />
<!--#if expr="$loginStatus = ''"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<p><code>#if expr="$loginStatus = 'anything'"</code> :<br />
<!--#if expr="$loginStatus = 'anything'"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
</body>
</html>
Screenshots
As rendered by Apache
As rendered by Node and node-ssi
The top and bottom parts of the test page are supposed to look the same, but the variable's value is changed by the last four #if statements. Note that the only time the = works as intended is the first one in the bottom section, and I assume it has something to do with the fact that that conditional is doing a numerical comparison instead of a string comparison.

