routeros-api-php icon indicating copy to clipboard operation
routeros-api-php copied to clipboard

fix: handle empty parseResponse for nested script execution (issue #136)

Open sonarta opened this issue 3 weeks ago • 0 comments

Problem

When executing a RouterOS script that calls another script (/system/script/run), the response may contain empty data blocks. This causes Undefined array key 0 error at line 377 of Client.php because parseResponse() returns an empty array [].

Solution

  • Replace inefficient double parseResponse() call with single call
  • Use !empty() and isset() checks to properly handle empty array responses
  • Add unit test for empty response edge case

Changes

  • src/Client.php: Fixed rosario() method to handle empty parseResponse result
  • tests/ClientTest.php: Added test_parseResponse_emptyArrayHandling() test

Testing

  • PHP syntax validation passed
  • Unit test added for the edge case

Fixes: #136

sonarta avatar Dec 10 '25 09:12 sonarta