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

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

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.

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.


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

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


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

{{ parent.tldr }}

{{ parent.urlSource.name }}