metaregistrar / php-epp-client

Object-oriented PHP EPP Client
https://www.metaregistrar.com/docs/
MIT License
210 stars 155 forks source link

addStreet in eppContactPostalInfo do not add the first address #173

Closed edermartins closed 5 years ago

edermartins commented 5 years ago

The code for addStreet do not add the first line in the array and add only 2 lines in the array. It need to be changed to:

    public function addStreet($street) {
        if ((is_string($street)) && (strlen($street) > 0)) {
            if ((is_array($this->street)) && (count($this->street) <= 3)) {
                $this->street[count($this->street)] = htmlspecialchars($street, ENT_COMPAT, "UTF-8");
            } else {
                throw new eppException('Cannot add more then 3 street names to postal info');
            }
        }
    }

Changes:

metaregistrar commented 5 years ago

Hello,

Is it possible that $this->street[count($this->street)-1] is a local amendment that you have made before? Because the repo i have already has $this->street[count($this->street)] = htmlspecialchars($street, ENT_COMPAT, "UTF-8"); No change necessary.

The purpose of this function is that it counts from 0 to 2, so after filling, $street[0], $street[1] and $street[2] should be filled. If i change the code to count($this->street) <= 3 then it would also fill $street[3], which is not intended.

I have tested the current code, without amendmends, using this test routine:

$postal = new \Metaregistrar\EPP\eppContactPostalInfo();
$postal->addStreet('Street 1');
$postal->addStreet('Street 2');
$postal->addStreet('Street 3');
$streets = $postal->getStreets();
var_dump($streets);

Result is as intended:

array(3) {
  [0]=>
  string(8) "Street 1"
  [1]=>
  string(8) "Street 2"
  [2]=>
  string(8) "Street 3"
}

Adding street number 4 gives me this: Metaregistrar\EPP\eppException: Cannot add more then 3 street names to postal info

edermartins commented 5 years ago

Sorry for that, I did a pull and the code is there. I am adding an extension for Brazil NicBR registrar.