Colons in YAML (view.yml)

Having just launched “Acme Video Website”, I tinkered with a few things, re-synced and got…

Warning: htmlentities() expects parameter 1 to be string, array given in /var/www/acme_video/docs/lib/symfony/config/sfViewConfigHandler.class.php on line 229

Ouchy. So I checked sfViewConfigHandler.class.php to see what was causing the fuss…

$data[] = sprintf(" \$response->addMeta('%s', '%s', false, false);", $name, str_replace('\'', '\\\'', preg_replace('/&(?=\w+;)/', '&', htmlentities($content, ENT_QUOTES, sfConfig::get('sf_charset')))));

Sadly, my regex is non-existent so I’m not entirely sure what’s being replace, however, it was obvious there was an illegal character defined in my meta keyword/description in my View.yml (actual title changed to protect anonimity of website)

title: Lorem ipsum dolor sit amet: consectetuer adipiscing elit.

Hmm, completely forgot about the colon there (after “amet”), whatever’s parsing the yml is obviously having a fit, and I need to leave that in there as the site owner wants to keep the original meta stuff for now.

So, tried \: to escape it, no deal! Time for a quick google, obviously…

According to the specifications for yml,
“Within double-quotes, special characters may be represented with c-style escape sequences starting with a blackslash”

title: "Lorem ipsum dolor sit amet\: consectetuer adipiscing elit."

Which physically put \: in the html that was generated, so removing the \ gave be the desired result. All I had to do was encase the entire line in quotes, (and checking the source of the generated html it was fine too, not doing anything funky like 2 sets of quotes, always worth checking!).

Sure enough, refering to the excellent “The Definitive Guide To Symfony” book, page 65 “Help, a YAML File Killed My App” shows exactly what I should have done anyway…

Todays lesson, don’t be so lazy, the book is only 2 meters across the corridor!

Written by baj | Posted on April 4th, 2008 in symfony |

One Comment to “Colons in YAML (view.yml)”

  1. Rob (the author) says:

    Good work Baj!

Leave a Reply