Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabs are not interpreded correctly ? #87

Open
stevenart opened this issue Apr 1, 2021 · 1 comment
Open

Tabs are not interpreded correctly ? #87

stevenart opened this issue Apr 1, 2021 · 1 comment

Comments

@stevenart
Copy link

If y have the following code in my YAML file :
primary: [section, key] (the character between "primary:" and "[sec..." is a tab [\t])
then the array is not parsed and returned as string :
Array ( [0] => name: i18n [1] => table: _i18n_site [2] => primary: [section, key]

But if i add a space before the tab, it works :
primary: [section, key] (two characters between "primary:" and "[sec..." = a space followed by a tab [\t])
then it works :
Array ( [0] => name: i18n [1] => table: _i18n_site [primary] => Array ( [0] => section [1] => key )

Both worked with spyc 0.5 but now with 0.6.2, it's not. Is there something I'm missing?

@stevenart stevenart changed the title Tabs are not interpreded correctly Tabs are not interpreded correctly ? Apr 1, 2021
@stevenart
Copy link
Author

stevenart commented Apr 1, 2021

I found the way to fix the behaviour of 0.6.2 to match 0.5. In the function returnKeyValuePair, I replaced the ": " string by simply ":". It now explodes on ":", not ": ".

private function returnKeyValuePair ($line) {
    $array = array();
    $key = '';
    if (strpos ($line, ':')) {
      // It's a key/value pair most likely
      // If the key is in double quotes pull it out
      if (($line[0] == '"' || $line[0] == "'") && preg_match('/^(["\'](.*)["\'](\s)*:)/',$line,$matches)) {    
        $value = trim(str_replace($matches[1],'',$line));
        $key   = $matches[2];
      } else {
        // Do some guesswork as to the key and the value
        $explode = explode(':', $line);
        $key     = trim(array_shift($explode));
        $value   = trim(implode(':', $explode));
        $this->checkKeysInValue($value);
      }
      // Set the type of the value.  Int, string, etc
      $value = $this->_toType($value);
      if ($key === '0') $key = '__!YAMLZero';
      $array[$key] = $value;
    } else {
      $array = array ($line);
    }
    return $array;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant