Skip to content
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

Fix the insertion of multiple domains as wildcard #3259

Open
wants to merge 2 commits into
base: development
Choose a base branch
from

Conversation

rdwebdesign
Copy link
Member

What does this PR aim to accomplish?

Fix #3257

When selecting the "Add domain as wildcard" checkbox with multiple domains, only the first one was changed into a wildcard regex.

How does this PR accomplish the above?

Changing kind variable from "exact" to "regex" only after the loop.

The issue happened because the previous code were modifying this variable inside the loop, but after the first domain, the check failed (the kind was wrongly changed before all domains were parsed) and the rest of the domains were not changed into wildcards.


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 and I have tested my changes.
  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)
  6. I have checked that another pull request for this purpose does not exist.
  7. I have considered, and confirmed that this submission will be valuable to others.
  8. I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  9. I give this submission freely, and claim no ownership to its content.

  • I have read the above and my PR is ready for review. Check this box to confirm

Comment on lines 502 to 507
// Transform domain to wildcard if specified by user
domains[i] = "(\\.|^)" + domains[i].replaceAll(".", "\\.") + "$";
kind = "regex";

// strip leading "*." if specified by user in wildcard mode
if (domains[i].startsWith("*.")) domains[i] = domains[i].substr(2);
}
Copy link
Member Author

@rdwebdesign rdwebdesign Feb 25, 2025

Choose a reason for hiding this comment

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

Looking at the code, I can see this:

If the user enters *.example.com the domain will be change into a wildcard (line 503) before the *. is removed (line 506, but the domain will never start with "*." after the previous line), resulting in this regex: (\.|^)*\.example\.com.
Is this intended?

The question is: *.example.com should be changed into what regex?

  • (\.|^)example\.com$ (every subdomains and also the main domain);
  • \.example\.com$ (only subdomains, but not the main domain);
  • (\.|^)*\.example\.com$ (same as above, but more complex to parse);

Copy link
Member

Choose a reason for hiding this comment

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

Is this intended?

I don't think so. I think the order here is wrong. The removal of *. was meant as a help because users entered domains like this and checked the wildcard box because they think they had to enter *. for it to become a wildcard.

The question is: *.example.com should be changed into what regex?

I think

(.|^)example.com$ (every subdomains and also the main domain);

Copy link
Member Author

Choose a reason for hiding this comment

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

Then I will change the order and remove the *. text before turning it into a regex.

Copy link
Member

Choose a reason for hiding this comment

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

In v5, it was explicitly the latter: all subdomains but not the domain itself. This is rather uncritical and non-breaking here as the checkbox is just a assistance tool for those inexperienced with regex. To me, *.abc.com does clearly not include abc.com itself, however, this is just me (and Pi-hole v5). You are perfectly right to ask "what would the user expect to happen". I don't know TBH. But @yubiuser may be right (include also the domain itself).

Copy link
Member Author

Choose a reason for hiding this comment

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

We can discuss this a little more before we decide. I don't want to change the previous behavior unless we have a good reason.

@rdwebdesign rdwebdesign requested a review from a team February 25, 2025 21:19
@rdwebdesign rdwebdesign requested a review from yubiuser February 26, 2025 17:25
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.

3 participants