-
Notifications
You must be signed in to change notification settings - Fork 17
Update me_connect.php to enhance the device response json content check #327
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
base: master
Are you sure you want to change the base?
Conversation
|
Test based on the request header wasn't bullet proof enough :
From my point of view it's better to simply check if the API call result is a valid Json or not. |
|
@vmonnier / @yguubiqube |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the JSON content detection logic in the Cisco NX REST adapter's connection handling. Instead of relying on Content-Type header checks, it now uses actual JSON parsing to determine if the response contains valid JSON content.
- Replaces Content-Type header inspection with direct JSON validation using
json_decode()andjson_last_error() - Consolidates JSON processing logic by removing the duplicate content-type checks
- Maintains existing functionality for session ID extraction and XML conversion
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| json_decode(preg_replace('/":([0-9]+)\.([0-9]+)/', '":"$1.$2"', $result)); | ||
| if (json_last_error() === JSON_ERROR_NONE ) { | ||
| $result=preg_replace('/":([0-9]+)\.([0-9]+)/', '":"$1.$2"', $result); | ||
| $array = json_decode ( $result, true ); |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The json_decode() call on line 169 is performing unnecessary work since its return value is discarded. The same regex replacement and JSON decoding is then repeated on line 171. Consider storing the result of the first json_decode() call to avoid duplicate processing.
| json_decode(preg_replace('/":([0-9]+)\.([0-9]+)/', '":"$1.$2"', $result)); | |
| if (json_last_error() === JSON_ERROR_NONE ) { | |
| $result=preg_replace('/":([0-9]+)\.([0-9]+)/', '":"$1.$2"', $result); | |
| $array = json_decode ( $result, true ); | |
| $json_result = preg_replace('/":([0-9]+)\.([0-9]+)/', '":"$1.$2"', $result); | |
| $array = json_decode($json_result, true); | |
| if (json_last_error() === JSON_ERROR_NONE ) { |
abr-ubiqube
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some suggestion form copilot
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No description provided.