Skip to content

Modernized _real_escape() and Added safety checks to query() - #23

Open
lenasterg wants to merge 3 commits into
wpmudev:masterfrom
lenasterg:master
Open

Modernized _real_escape() and Added safety checks to query()#23
lenasterg wants to merge 3 commits into
wpmudev:masterfrom
lenasterg:master

Conversation

@lenasterg

Copy link
Copy Markdown
Contributor

Modernized _real_escape():

  • Added scalar validation (is_scalar()) to safely handle arrays/objects.
  • Integrated _doing_it_wrong() warnings and addslashes() fallback when no active global database connection is present.
  • Appended WordPress placeholder escaping via add_placeholder_escape().

Robust query() Execution:

  • Added safety checks to ensure $this->result is a valid mysqli_result object before attempting to fetch data (improves handling for non-result queries like BEGIN/COMMIT).
  • Cleaned up string formatting, error logging, and carriage return handling.

Code Quality & Formatting: Cleaned up code comments, spacing, and regex matching consistency across query analysis methods.

 - Bug Fix: Added a safety check (is_object) on $this->result within the query handler to safely process non-result queries (such as BEGIN and COMMIT), preventing Fatal Error crashes on tables or environments where transactions are not supported or return boolean values.
-  Code Quality: Refactored the query() method to strictly comply with WordPress Coding Standards (WPCS).
### Bug Fix & Enhancements: Multi-DB Query Analysis for `SHOW CREATE TABLE`

- **Fixed Database Routing for `SHOW CREATE TABLE` Queries:** Updated the `analyze_query()` method in the `m_wpdb` class to correctly parse and route queries that explicitly include database names and backticks (e.g., `SHOW CREATE TABLE \`db_name\`.\`table_name\``).
- **Improved Regex Flexibility:** Enhanced pattern matching to seamlessly support table names with or without database prefixes, schema identifiers, and backticks.
- Add scalar validation using is_scalar() to handle non-scalar data safely.
- Implement error handling with _doing_it_wrong() and fallback to addslashes().
- Integrate add_placeholder_escape() for modern WordPress SQL placeholders.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant