Skip to content

Conversation

DL6ER
Copy link
Member

@DL6ER DL6ER commented Jul 2, 2025

What does this implement/fix?

See title. Discussion ongoing in that issue ticket, hence, opening in draft mode here

If user use _ when matching domains or clients, this will not match a literal underscore but act as the SQLite3 default single-character wildcard. This PR allows users to escape underscores in domains/clients by escaping their underscore like \_. This was not possible before.


Related issue or feature (if applicable): Fixes #2549

Pull request in docs with documentation (if applicable): N/A


By submitting this pull request, I confirm the following:

  1. I have read and understood the contributors guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
  2. I have commented my proposed changes within the code.
  3. I am willing to help maintain this change if there are issues with it later.
  4. It is compatible with the EUPL 1.2 license
  5. I have squashed any insignificant commits. (git rebase)

Checklist:

  • The code change is tested and works locally.
  • I based my code and PRs against the repositories development branch.
  • I signed off all commits. Pi-hole enforces the DCO for all contributions
  • I signed all my commits. Pi-hole requires signatures to verify authorship
  • I have read the above and my PR is ready for review.

@DL6ER DL6ER force-pushed the fix/escape_underscore branch from 712edc1 to 2c101fa Compare August 9, 2025 08:03
@DL6ER DL6ER marked this pull request as ready for review August 9, 2025 08:04
@DL6ER DL6ER requested a review from a team as a code owner August 9, 2025 08:04
@DL6ER DL6ER changed the title Escape special single-character wildcard "_" when doing partial matching Allow escaping special single-character wildcard "_" when doing partial matching Aug 9, 2025
@DL6ER DL6ER requested a review from rrobgill August 9, 2025 08:06
@DL6ER
Copy link
Member Author

DL6ER commented Aug 9, 2025

Related documentation on the web interface: pi-hole/web#3578

Copy link
Contributor

@rrobgill rrobgill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All working correctly both via API, and through the web interface.

Escaped underscore now searches correctly, and unescaped underscore remains as single character wildcard.

@DL6ER DL6ER requested a review from Copilot September 17, 2025 06:53
Copy link

@Copilot Copilot AI left a 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 enables escaping of underscore characters in domain and client name searches to prevent unintended wildcard matching. By default, SQLite treats _ as a single-character wildcard, but users can now escape underscores with \_ to match literal underscore characters.

  • Add ESCAPE '\\' clause to SQL LIKE queries to enable backslash escaping
  • Increase buffer allocation for like_name to accommodate escaped characters
  • Replace sprintf with snprintf for safer string formatting

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/database/gravity-db.c Add ESCAPE clause to LIKE queries and improve memory allocation/string formatting
src/api/queries.c Add ESCAPE clause to domain and client search queries

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

DL6ER added 3 commits October 4, 2025 09:20
…s/adlists/clients/gravity/domainlist matching

Signed-off-by: DL6ER <dl6er@dl6er.de>
…ing for the Query Log table

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
@DL6ER DL6ER force-pushed the fix/escape_underscore branch from 76b19e0 to e0037e6 Compare October 4, 2025 07:21
@DL6ER
Copy link
Member Author

DL6ER commented Oct 4, 2025

Rebased onto latest development. This reduces the number of commits from 5 to 3.

@DL6ER DL6ER merged commit e8a8447 into development Oct 4, 2025
18 checks passed
@DL6ER DL6ER deleted the fix/escape_underscore branch October 4, 2025 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants