Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Wildflower CMS and Unterminated String Literal Error

DZone's Guide to

Wildflower CMS and Unterminated String Literal Error

· Web Dev Zone
Free Resource

Deploying code to production can be filled with uncertainty. Reduce the risks, and deploy earlier and more often. Download this free guide to learn more. Brought to you in partnership with Rollbar.

I've been developing a site using Wildflower CMS developed using CakePHP and ran into an infuriating problem. After working on it for several weeks without issue I started receiving javascript errors that caused everything to come to a grinding halt. The errors were all reported using Firebug and the javascript debugger. The culprit:

Unterminated String Literal

After that in the Firebug console was:

$ is not defined

I knew there was a strong possibility that the first error was somehow causing the second and that top-down debugging was the way to go. After inspecting the javascript code I discovered that there was a variable assignment going on that spanned several lines. This might be legal in PHP but not javascript. For example:

foobar = 'multi 
line
assignment';

NO GOOD.

So what was causing this? Why wasn't Wildflower's JLM packager stripping newlines out? After some digging I found the method that was supposed to be doing just that and noticed it was only removing new lines, not carriage returns.

The Fix

/wildflower/controllers/components/jlm_packager.php

// Line ~139 in JlmPackagerComponent::readTemplates  
// Change
$template = str_replace(array("\n", "'"), array('', "\'"), $template);
// to
$template = str_replace(array("\n", "'", "\r"), array('', "\'", ""), $template);

As you can tell, I just added carriage returns to the list of characters to be removed or altered (in this case removed). Initially this was never a problem. Only after I copied files down from a unix server to my windows machine did this start to occur. Hopefully this saves someone else some time.

Deploying code to production can be filled with uncertainty. Reduce the risks, and deploy earlier and more often. Download this free guide to learn more. Brought to you in partnership with Rollbar.

Topics:

Published at DZone with permission of Mike Bernat, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}