Over a million developers have joined DZone.

Wildflower CMS and Unterminated String Literal Error

DZone's Guide to

Wildflower CMS and Unterminated String Literal Error

· Web Dev Zone ·
Free Resource

Access over 20 APIs and mobile SDKs, up to 250k transactions free with no credit card required

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 


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


// 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.

#1 for location developers in quality, price and choice, switch to HERE.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}