component-ini icon indicating copy to clipboard operation
component-ini copied to clipboard

Mismatch between encoding and decoding of boolean values.

Open high-rolls opened this issue 1 year ago • 2 comments

IniWriter's encode method encodes boolean values as either 1 or 0, but IniReader's decode reads 1 and 0 as integer values. When reading and writing the same .ini file array using the library, all boolean values will be converted to integers.

high-rolls avatar Aug 30 '24 15:08 high-rolls

Hello @high-rolls can you please provide us with the following information to help us better triage this issue?

  1. Current Behaviour or What happened?
  2. Expected Behaviour or What should happen?
  3. How can this be reproduced?
  4. Customer or Website Name
  5. On Prem or Cloud
  6. Matomo major version including minor / patch version
  7. PHP version
  8. Database
  9. What browsers are you seeing the problem on?
  10. Relevant log output and/or screenshots

Thank you in advance.

achakko avatar Sep 10 '24 20:09 achakko

Hello @achakko , here's the information you need:

  1. Using an object of the IniWriter class to write boolean values will write them as 0 or 1 to a file. Later, when I read from the same file using an IniReader object, I get an array containing integer values where the booleans should be, because the numbers 0 and 1 are interpreted as integers.
  2. The IniWriter class should write the standard values for booleans, 'true' and 'false', which are already read correctly as booleans by the IniReader class.
  3. With the following code:
<?php
require 'vendor/autoload.php';

use Matomo\Ini\{IniReader, IniWriter};

$writer = new IniWriter();
$iniArray = ['Section 1' => ['test' => true]];
$writer->writeToFile('bool_test.ini', $iniArray);
$reader = new IniReader();
$readArray = $reader->readFile('bool_test.ini');
echo gettype($readArray['Section 1']['test']); // 'boolean' expected, got 'integer' instead
?>
  1. I'm not a customer, I'm just using this library for a personal project.
  2. N/A
  3. I use only this component, version 3.0.1
  4. PHP version 8.2.12
  5. N/A
  6. N/A
  7. N/A #

Also, here's the linked PR: #26

high-rolls avatar Sep 30 '24 02:09 high-rolls