matomo-org / component-ini

Read and write INI configurations.
GNU Lesser General Public License v3.0
50 stars 25 forks source link

Mismatch between encoding and decoding of boolean values. #25

Open high-rolls opened 2 months ago

high-rolls commented 2 months ago

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.

achakko commented 2 months ago

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.

high-rolls commented 1 month ago

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 ?>


4. I'm not a customer, I'm just using this library for a personal project.
5. N/A
6. I use only this component, version 3.0.1
7. PHP version 8.2.12
8. N/A
9. N/A
10. N/A #

Also, here's the linked PR: #26