Thread

Date format variable detection missing colon from regex. Was present in previous versions.

February 26, 2014 11:43am

Subscribe [3]
  • #1 / Feb 26, 2014 11:43am

    Greg Ferrell's avatar

    Greg Ferrell

    102 posts

    In

    system/expressionengine/libraries/Template.php->_match_date_vars()

    In previous versions the regex for matching date fields allowed for a colon:

    if (preg_match_all("/".LD."([\w:\-]+)\s+format=[\"'](.*?)[\"']".RD."/", $str, $matches, PREG_SET_ORDER))

    In EE 2.8 beta 2, the colon is removed for some reason:

    if ($standard = preg_match_all("/".LD."([\w\-]+)\s+(format|timezone)=[\"'](.*?)[\"']".RD."/", $str, $matches, PREG_SET_ORDER))

    I’m assuming that this is to allow for matching of the new ‘:relative’ keyword, but this breaks some longtime usage of colon prefixed vars that I know ourselves and DevDemon use off of the top of my head.

    For instance: in EE 2.7.3,

    {freeform:edit_date format="%Y-%m-%d"}

    works when using TMPL->parse_variables. In EE 2.8 it does not due to the removal of the colon from the regex.

  • #2 / Feb 26, 2014 12:05pm

    Seth Barber's avatar

    Seth Barber

    128 posts

    Thanks for catching this. I have adjusted the flow of that function catching relative dates first, and restored the colon when searching for other dates. This will be in the 2.8.0 release.

    Here is the diff of the change:

    diff --git a/system/expressionengine/libraries/Template.php b/system/expressionengine/libraries/Template.php
    index 2c38e11..5b54dae 100644
    --- a/system/expressionengine/libraries/Template.php
    +++ b/system/expressionengine/libraries/Template.php
    @@ -4146,15 +4146,14 @@ class EE_Template {
        strpos($str, 'timezone=') !== FALSE ||
        strpos($str, ':relative') !== FALSE)
       {
    -   if ($standard = preg_match_all("/".LD."([\w\-]+)\s+(format|timezone)=[\"'](.*?)[\"']".RD."/", $str, $matches, PREG_SET_ORDER))
    +   if ($relative = preg_match_all("/".LD."([\w\-]+):relative(.*?)".RD."/", $str, $matches, PREG_SET_ORDER))
        {
         foreach ($matches as $match)
         {
          $this->date_vars[] = $match[1];
         }
        }
    -
    -   if ($relative = preg_match_all("/".LD."([\w\-]+):relative(.*?)".RD."/", $str, $matches, PREG_SET_ORDER))
    +   elseif ($standard = preg_match_all("/".LD."([\w:\-]+)\s+(format|timezone)=[\"'](.*?)[\"']".RD."/", $str, $matches, PREG_SET_ORDER))
        {
         foreach ($matches as $match)
         {
  • #3 / Feb 26, 2014 12:05pm

    Brad Parscale

    196 posts

    Hello,

    This is a big issue for us. All of our addons would break. We need a workaround or have it fixed. Thanks for the catch Greg!

    Brad

  • #4 / Feb 26, 2014 12:06pm

    Brad Parscale

    196 posts

    We posted the same minute. Thank you Seth. Could we still have a Beta 3 to test?

    Brad

  • #5 / Feb 26, 2014 12:07pm

    Greg Ferrell's avatar

    Greg Ferrell

    102 posts

    Thanks, Seth.

    “This will be in the 2.8.0 release.”

    Am I taking this to understand that there will be no third beta before release?

  • #6 / Feb 26, 2014 2:37pm

    Seth Barber's avatar

    Seth Barber

    128 posts

    I added a diff to the solution.

ExpressionEngine News

#eecms, #events, #releases