web icon indicating copy to clipboard operation
web copied to clipboard

fix: add urls with space

Open codomposer opened this issue 3 weeks ago • 5 comments

Thank you for your contribution to the Pi-hole Community!

Please read the comments below to help us consider your Pull Request.

We are all volunteers and completing the process outlined will help us review your commits quicker.

Please make sure you

  1. Base your code and PRs against the repositories developmental branch.
  2. Sign Off all commits as we enforce the DCO for all contributions
  3. Sign all your commits as they must have verified signatures
  4. File a pull request for any change that requires changes to our documentation at our documentation repo

What does this PR aim to accomplish?:

Closes #3364

Fix: URLs with spaces can now be added to blocklist/allowlist

Problem

  • URLs containing spaces were being incorrectly split into multiple parts
  • Attempting to use %20 encoding resulted in double-encoding to %2520
  • Root cause: The input splitting regex /[\s,]+/ treated spaces as delimiters

How does this PR accomplish the above?:

Solution

  • Changed split pattern from /[\s,]+/ to /[,\n]+/ in groups-lists.js
  • URLs with spaces are now preserved correctly
  • Multiple URLs can still be added using commas or newlines as separators
  • Updated UI hint to reflect the new behavior

Link documentation PRs if any are needed to support this PR:


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.

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

Contribution by Gittensor, learn more at https://gittensor.io/

codomposer avatar Dec 02 '25 10:12 codomposer

This may not be the best approach for a couple of reasons.

URLs cannot contain spaces but they can contain commas (https://datatracker.ietf.org/doc/html/rfc3986#section-2).

Other fields in the webUI use both spaces and newlines as field delimiters, this change would have different behaviour in different text input fields.

./groups-clients.js:  // Check if the user wants to add multiple IPs (space or newline separated)
./groups-lists.js:  // Check if the user wants to add multiple domains (space or newline separated)
./groups-domains.js:  // Check if the user wants to add multiple domains (space or newline separated)
./groups.js:  // Check if the user wants to add multiple groups (space or newline separated)

There seems to be a simpler fix which to allow people to enter URLs containing %20 for a "space", without interfering with other URLs or altering the accepted delimiters:

diff --git a/scripts/js/groups-lists.js b/scripts/js/groups-lists.js
index 47c3db92..4b700582 100644
--- a/scripts/js/groups-lists.js
+++ b/scripts/js/groups-lists.js
@@ -584,7 +584,7 @@ function editList() {
   utils.disableAll();
   utils.showAlert("info", "", "Editing address...", address);
   $.ajax({
-    url: document.body.dataset.apiurl + "/lists/" + encodeURIComponent(address) + "?type=" + type,
+    url: document.body.dataset.apiurl + "/lists/" + encodeURIComponent(address).replace(/%2520/g, "%20") + "?type=" + type,
     method: "put",
     dataType: "json",
     processData: false,
image

rrobgill avatar Dec 03 '25 03:12 rrobgill

@rrobgill can you check the update again?

codomposer avatar Dec 03 '25 04:12 codomposer

@rrobgill can you check the update again?

image

New approach tests ok for me.

rrobgill avatar Dec 03 '25 04:12 rrobgill

@rrobgill can you check the update again?

image New approach tests ok for me.

then can you merge it?

codomposer avatar Dec 03 '25 12:12 codomposer

@rrobgill

codomposer avatar Dec 04 '25 20:12 codomposer

@codomposer please don't ping people for merge - PRs are prioritised on a "when we can get to it" basis, which is just the unfortunate nature of having to balance "real jobs" and this one.

(besides, rrobgill is a contributor but does not have merge rights)

PromoFaux avatar Dec 05 '25 10:12 PromoFaux