Pihole -q error

When checking a domain against the list in the CL I get an error:

pihole -q gateway.fe.apple-dns.net
parse error: Invalid escape at line 14, column 37
parse error: Invalid escape at line 14, column 37
Found  domains exactly matching 'gateway.fe.apple-dns.net'.

/opt/pihole/query.sh: 66: [: Illegal number: 
Found  adlists exactly matching 'gateway.fe.apple-dns.net'.

/opt/pihole/query.sh: 79: [: Illegal number: 

Other domains I try seem to be fine. Also, the web interface seems to be fine also when using gateway.fe.apple-dns.net in the query lists page.

debug token

Can you please try this command and post the output?

bash -x /opt/pihole/query.sh -q gateway.fe.apple-dns.net
$ bash -x /opt/pihole/query.sh -q gateway.fe.apple-dns.net
+ PI_HOLE_INSTALL_DIR=/opt/pihole
+ max_results=20
+ partial=false
+ domain=
+ colfile=/opt/pihole/COL_TABLE
+ . /opt/pihole/COL_TABLE
++ '[' -t 1 ']'
+++ tput colors
++ '[' 8 -ge 8 ']'
++ COL_BOLD=''
++ COL_ULINE=''
++ COL_NC=''
++ COL_GRAY=''
++ COL_RED=''
++ COL_GREEN=''
++ COL_YELLOW=''
++ COL_BLUE=''
++ COL_PURPLE=''
++ COL_CYAN=''
++ COL_WHITE=''
++ COL_BLACK=''
++ COL_LIGHT_BLUE=''
++ COL_LIGHT_GREEN=''
++ COL_LIGHT_CYAN=''
++ COL_LIGHT_RED=''
++ COL_URG_RED=''
++ COL_LIGHT_PURPLE=''
++ COL_BROWN=''
++ COL_LIGHT_GRAY=''
++ COL_DARK_GRAY=''
++ TICK='[✓]'
++ CROSS='[✗]'
++ INFO='[i]'
++ QST='[?]'
++ DONE=' done!'
++ OVER='\r'
+ . /opt/pihole/api.sh
+ '[' 2 -gt 0 ']'
+ case "$1" in
+ domain=-q
+ shift
+ '[' 1 -gt 0 ']'
+ case "$1" in
+ domain=gateway.fe.apple-dns.net
+ shift
+ '[' 0 -gt 0 ']'
+ Main gateway.fe.apple-dns.net
+ local data
+ '[' -z gateway.fe.apple-dns.net ']'
+ TestAPIAvailability
+ local chaos_api_list availabilityResonse
++ dig +short chaos txt local.api.ftl @127.0.0.1
+ chaos_api_list='"http://localhost:80/api/" "https://localhost:443/api/"'
+ '[' -z '"http://localhost:80/api/" "https://localhost:443/api/"' ']'
+ '[' -n '"http://localhost:80/api/" "https://localhost:443/api/"' ']'
+ API_URL='"http://localhost:80/api/"'
+ API_URL='"http://localhost:80/api/'
+ API_URL=http://localhost:80/api/
++ curl -skS -o /dev/null -w '%{http_code}' http://localhost:80/api/auth
+ availabilityResonse=401
+ '[' '!' 401 = 200 ']'
+ '[' '!' 401 = 401 ']'
+ break
+ '[' -n '' ']'
++ GetFTLData 'search/gateway.fe.apple-dns.net?N=20&partial=false'
++ local data response status
+++ curl -skS -w '%{http_code}' -X GET 'http://localhost:80/api/search/gateway.fe.apple-dns.net?N=20&partial=false' -H 'Accept: application/json' -H 'sid: '
++ response='{
        "search":       {
                "domains":      [{
                                "domain":       "(\\.|^)apple-dns\\.net$",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Apple Stuff",
                                "enabled":      true,
                                "id":   98,
                                "date_added":   1612976995,
                                "date_modified":        1701784855,
                                "groups":       [0, 1, 2, 5, 6]
                        }, {
                                "domain":       ".*;querytype=AAAA",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Allow AAAA for DS",
                                "enabled":      true,
                                "id":   124,
                                "date_added":   1626524249,
                                "date_modified":        1640729430,
                                "groups":       [5]
                        }, {
                                "domain":       ".*;querytype=AAAA;reply=nodata",
                                "type": "deny",
                                "kind": "regex",
                                "comment":      "Block AAAA requests",
                                "enabled":      true,
                                "id":   136,
                                "date_added":   1640750358,
                                "date_modified":        1648095365,
                                "groups":       [0]
                        }],
                "gravity":      [],
                "results":      {
                        "domains":      {
                                "exact":        0,
                                "regex":        3
                        },
                        "gravity":      {
                                "allow":        0,
                                "block":        0
                        },
                        "total":        3
                },
                "parameters":   {
                        "N":    20,
                        "partial":      false,
                        "domain":       "gateway.fe.apple-dns.net",
                        "debug":        false
                }
        },
        "took": 0.00517559051513672
}200'
+++ printf %s 200
++ status=200
+++ printf %s '{
        "search":       {
                "domains":      [{
                                "domain":       "(\\.|^)apple-dns\\.net$",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Apple Stuff",
                                "enabled":      true,
                                "id":   98,
                                "date_added":   1612976995,
                                "date_modified":        1701784855,
                                "groups":       [0, 1, 2, 5, 6]
                        }, {
                                "domain":       ".*;querytype=AAAA",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Allow AAAA for DS",
                                "enabled":      true,
                                "id":   124,
                                "date_added":   1626524249,
                                "date_modified":        1640729430,
                                "groups":       [5]
                        }, {
                                "domain":       ".*;querytype=AAAA;reply=nodata",
                                "type": "deny",
                                "kind": "regex",
                                "comment":      "Block AAAA requests",
                                "enabled":      true,
                                "id":   136,
                                "date_added":   1640750358,
                                "date_modified":        1648095365,
                                "groups":       [0]
                        }],
                "gravity":      [],
                "results":      {
                        "domains":      {
                                "exact":        0,
                                "regex":        3
                        },
                        "gravity":      {
                                "allow":        0,
                                "block":        0
                        },
                        "total":        3
                },
                "parameters":   {
                        "N":    20,
                        "partial":      false,
                        "domain":       "gateway.fe.apple-dns.net",
                        "debug":        false
                }
        },
        "took": 0.00517559051513672
}'
++ data='{
        "search":       {
                "domains":      [{
                                "domain":       "(\\.|^)apple-dns\\.net$",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Apple Stuff",
                                "enabled":      true,
                                "id":   98,
                                "date_added":   1612976995,
                                "date_modified":        1701784855,
                                "groups":       [0, 1, 2, 5, 6]
                        }, {
                                "domain":       ".*;querytype=AAAA",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Allow AAAA for DS",
                                "enabled":      true,
                                "id":   124,
                                "date_added":   1626524249,
                                "date_modified":        1640729430,
                                "groups":       [5]
                        }, {
                                "domain":       ".*;querytype=AAAA;reply=nodata",
                                "type": "deny",
                                "kind": "regex",
                                "comment":      "Block AAAA requests",
                                "enabled":      true,
                                "id":   136,
                                "date_added":   1640750358,
                                "date_modified":        1648095365,
                                "groups":       [0]
                        }],
                "gravity":      [],
                "results":      {
                        "domains":      {
                                "exact":        0,
                                "regex":        3
                        },
                        "gravity":      {
                                "allow":        0,
                                "block":        0
                        },
                        "total":        3
                },
                "parameters":   {
                        "N":    20,
                        "partial":      false,
                        "domain":       "gateway.fe.apple-dns.net",
                        "debug":        false
                }
        },
        "took": 0.00517559051513672
}'
++ '[' 200 = 200 ']'
++ echo '{
        "search":       {
                "domains":      [{
                                "domain":       "(\\.|^)apple-dns\\.net$",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Apple Stuff",
                                "enabled":      true,
                                "id":   98,
                                "date_added":   1612976995,
                                "date_modified":        1701784855,
                                "groups":       [0, 1, 2, 5, 6]
                        }, {
                                "domain":       ".*;querytype=AAAA",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Allow AAAA for DS",
                                "enabled":      true,
                                "id":   124,
                                "date_added":   1626524249,
                                "date_modified":        1640729430,
                                "groups":       [5]
                        }, {
                                "domain":       ".*;querytype=AAAA;reply=nodata",
                                "type": "deny",
                                "kind": "regex",
                                "comment":      "Block AAAA requests",
                                "enabled":      true,
                                "id":   136,
                                "date_added":   1640750358,
                                "date_modified":        1648095365,
                                "groups":       [0]
                        }],
                "gravity":      [],
                "results":      {
                        "domains":      {
                                "exact":        0,
                                "regex":        3
                        },
                        "gravity":      {
                                "allow":        0,
                                "block":        0
                        },
                        "total":        3
                },
                "parameters":   {
                        "N":    20,
                        "partial":      false,
                        "domain":       "gateway.fe.apple-dns.net",
                        "debug":        false
                }
        },
        "took": 0.00517559051513672
}'
+ data='{
        "search":       {
                "domains":      [{
                                "domain":       "(\\.|^)apple-dns\\.net$",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Apple Stuff",
                                "enabled":      true,
                                "id":   98,
                                "date_added":   1612976995,
                                "date_modified":        1701784855,
                                "groups":       [0, 1, 2, 5, 6]
                        }, {
                                "domain":       ".*;querytype=AAAA",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Allow AAAA for DS",
                                "enabled":      true,
                                "id":   124,
                                "date_added":   1626524249,
                                "date_modified":        1640729430,
                                "groups":       [5]
                        }, {
                                "domain":       ".*;querytype=AAAA;reply=nodata",
                                "type": "deny",
                                "kind": "regex",
                                "comment":      "Block AAAA requests",
                                "enabled":      true,
                                "id":   136,
                                "date_added":   1640750358,
                                "date_modified":        1648095365,
                                "groups":       [0]
                        }],
                "gravity":      [],
                "results":      {
                        "domains":      {
                                "exact":        0,
                                "regex":        3
                        },
                        "gravity":      {
                                "allow":        0,
                                "block":        0
                        },
                        "total":        3
                },
                "parameters":   {
                        "N":    20,
                        "partial":      false,
                        "domain":       "gateway.fe.apple-dns.net",
                        "debug":        false
                }
        },
        "took": 0.00517559051513672
}'
+ '[' '{
        "search":       {
                "domains":      [{
                                "domain":       "(\\.|^)apple-dns\\.net$",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Apple Stuff",
                                "enabled":      true,
                                "id":   98,
                                "date_added":   1612976995,
                                "date_modified":        1701784855,
                                "groups":       [0, 1, 2, 5, 6]
                        }, {
                                "domain":       ".*;querytype=AAAA",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Allow AAAA for DS",
                                "enabled":      true,
                                "id":   124,
                                "date_added":   1626524249,
                                "date_modified":        1640729430,
                                "groups":       [5]
                        }, {
                                "domain":       ".*;querytype=AAAA;reply=nodata",
                                "type": "deny",
                                "kind": "regex",
                                "comment":      "Block AAAA requests",
                                "enabled":      true,
                                "id":   136,
                                "date_added":   1640750358,
                                "date_modified":        1648095365,
                                "groups":       [0]
                        }],
                "gravity":      [],
                "results":      {
                        "domains":      {
                                "exact":        0,
                                "regex":        3
                        },
                        "gravity":      {
                                "allow":        0,
                                "block":        0
                        },
                        "total":        3
                },
                "parameters":   {
                        "N":    20,
                        "partial":      false,
                        "domain":       "gateway.fe.apple-dns.net",
                        "debug":        false
                }
        },
        "took": 0.00517559051513672
}' = 401 ']'
+ GenerateOutput '{
        "search":       {
                "domains":      [{
                                "domain":       "(\\.|^)apple-dns\\.net$",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Apple Stuff",
                                "enabled":      true,
                                "id":   98,
                                "date_added":   1612976995,
                                "date_modified":        1701784855,
                                "groups":       [0, 1, 2, 5, 6]
                        }, {
                                "domain":       ".*;querytype=AAAA",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Allow AAAA for DS",
                                "enabled":      true,
                                "id":   124,
                                "date_added":   1626524249,
                                "date_modified":        1640729430,
                                "groups":       [5]
                        }, {
                                "domain":       ".*;querytype=AAAA;reply=nodata",
                                "type": "deny",
                                "kind": "regex",
                                "comment":      "Block AAAA requests",
                                "enabled":      true,
                                "id":   136,
                                "date_added":   1640750358,
                                "date_modified":        1648095365,
                                "groups":       [0]
                        }],
                "gravity":      [],
                "results":      {
                        "domains":      {
                                "exact":        0,
                                "regex":        3
                        },
                        "gravity":      {
                                "allow":        0,
                                "block":        0
                        },
                        "total":        3
                },
                "parameters":   {
                        "N":    20,
                        "partial":      false,
                        "domain":       "gateway.fe.apple-dns.net",
                        "debug":        false
                }
        },
        "took": 0.00517559051513672
}'
+ local data gravity_data lists_data num_gravity num_lists search_type_str
+ local gravity_data_csv lists_data_csv line current_domain
+ data='{
        "search":       {
                "domains":      [{
                                "domain":       "(\\.|^)apple-dns\\.net$",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Apple Stuff",
                                "enabled":      true,
                                "id":   98,
                                "date_added":   1612976995,
                                "date_modified":        1701784855,
                                "groups":       [0, 1, 2, 5, 6]
                        }, {
                                "domain":       ".*;querytype=AAAA",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Allow AAAA for DS",
                                "enabled":      true,
                                "id":   124,
                                "date_added":   1626524249,
                                "date_modified":        1640729430,
                                "groups":       [5]
                        }, {
                                "domain":       ".*;querytype=AAAA;reply=nodata",
                                "type": "deny",
                                "kind": "regex",
                                "comment":      "Block AAAA requests",
                                "enabled":      true,
                                "id":   136,
                                "date_added":   1640750358,
                                "date_modified":        1648095365,
                                "groups":       [0]
                        }],
                "gravity":      [],
                "results":      {
                        "domains":      {
                                "exact":        0,
                                "regex":        3
                        },
                        "gravity":      {
                                "allow":        0,
                                "block":        0
                        },
                        "total":        3
                },
                "parameters":   {
                        "N":    20,
                        "partial":      false,
                        "domain":       "gateway.fe.apple-dns.net",
                        "debug":        false
                }
        },
        "took": 0.00517559051513672
}'
++ echo '{
        "search":       {
                "domains":      [{
                                "domain":       "(\\.|^)apple-dns\\.net$",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Apple Stuff",
                                "enabled":      true,
                                "id":   98,
                                "date_added":   1612976995,
                                "date_modified":        1701784855,
                                "groups":       [0, 1, 2, 5, 6]
                        }, {
                                "domain":       ".*;querytype=AAAA",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Allow AAAA for DS",
                                "enabled":      true,
                                "id":   124,
                                "date_added":   1626524249,
                                "date_modified":        1640729430,
                                "groups":       [5]
                        }, {
                                "domain":       ".*;querytype=AAAA;reply=nodata",
                                "type": "deny",
                                "kind": "regex",
                                "comment":      "Block AAAA requests",
                                "enabled":      true,
                                "id":   136,
                                "date_added":   1640750358,
                                "date_modified":        1648095365,
                                "groups":       [0]
                        }],
                "gravity":      [],
                "results":      {
                        "domains":      {
                                "exact":        0,
                                "regex":        3
                        },
                        "gravity":      {
                                "allow":        0,
                                "block":        0
                        },
                        "total":        3
                },
                "parameters":   {
                        "N":    20,
                        "partial":      false,
                        "domain":       "gateway.fe.apple-dns.net++ jq '.search.domains | [.[] | {domain: .domain, type: .type}]'
",
                        "debug":        false
                }
        },
        "took": 0.00517559051513672
}'
+ lists_data='[
  {
    "domain": "(\\.|^)apple-dns\\.net$",
    "type": "allow"
  },
  {
    "domain": ".*;querytype=AAAA",
    "type": "allow"
  },
  {
    "domain": ".*;querytype=AAAA;reply=nodata",
    "type": "deny"
  }
]'
++ echo '{
        "search":       {
                "domains":      [{
                                "domain":       "(\\.|^)apple-dns\\.net$",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Apple Stuff",
                                "enabled":      true,
                                "id":   98,
                                "date_added":   1612976995,
                                "date_modified":        1701784855,
                                "groups":       [0, 1, 2, 5, 6]
                        }, {
                                "domain":       ".*;querytype=AAAA",
                                "type": "allow",
                                "kind": "regex",
                                "comment":      "Allow AAAA for DS",
                                "enabled":      true,
                                "id":   124,
                                "date_added":   1626524249,
                                "date_modified":        1640729430,
                                "groups":       [5]
                        }, {
                                "domain":       ".*;querytype=AAAA;reply=nodata",
                                "type": "deny",
                                "kind": "regex",
                                "comment":      "Block AAAA requests",
                                "enabled":      true,
                                "id":   136,
                                "date_added":   1640750358,
                                "date_modified":        1648095365,
                                "groups":       [0]
                        }],
                "gravity":      [],
                "results":      {
                        "domains":      {
                                "exact":        0,
                                "regex":        3
                        },
                        "gravity":      {
                                "allow":        0,
                                "block":        0
                        },
                        "total":        3
                },
                "parameters":   {
                        "N":    20,
                        "partial":      false,
                        "domain":       "gateway.fe.apple-dns.net++ jq '.search.gravity  | group_by(.address) | map({ address: (.[0].address), domains: [.[] | .domain] })'
",
                        "debug":        false
                }
        },
        "took": 0.00517559051513672
}'
+ gravity_data='[]'
++ echo '[]'
++ jq length
+ num_gravity=0
++ echo '[
  {
    "domain": "(\\.|^)apple-dns\\.net$",
    "type": "allow"
  },
  {
    "domain": ".*;querytype=AAAA",
    "type": "allow"
  },
  {
    "domain": ".*;querytype=AAAA;reply=nodata",
    "type": "deny"
  }
]'
++ jq length
+ num_lists=3
+ '[' false = true ']'
+ search_type_str=exactly
+ printf '%s\n\n' 'Found 3 domains exactly matching '\''gateway.fe.apple-dns.net'\''.'
Found 3 domains exactly matching 'gateway.fe.apple-dns.net'.

+ '[' 3 -gt 0 ']'
++ echo '[
  {
    "domain": "(\\.|^)apple-dns\\.net$",
    "type": "allow"
  },
  {
    "domain": ".*;querytype=AAAA",
    "type": "allow"
  },
  {
    "domain": ".*;querytype=AAAA;reply=nodata",
    "type": "deny"
  }
]'
++ jq --raw-output '.[] | [.domain, .type] | join(",")'
+ lists_data_csv='(\.|^)apple-dns\.net$,allow
.*;querytype=AAAA,allow
.*;querytype=AAAA;reply=nodata,deny'
+ echo '(\.|^)apple-dns\.net$,allow
.*;querytype=AAAA,allow
.*;querytype=AAAA;reply=nodata,deny'
+ read -r line
+ printf '%s\n\n' '  - (\.|^)apple-dns\.net$ (type: exact allow domain)'
  - (\.|^)apple-dns\.net$ (type: exact allow domain)

+ read -r line
+ printf '%s\n\n' '  - .*;querytype=AAAA (type: exact allow domain)'
  - .*;querytype=AAAA (type: exact allow domain)

+ read -r line
+ printf '%s\n\n' '  - .*;querytype=AAAA;reply=nodata (type: exact deny domain)'
  - .*;querytype=AAAA;reply=nodata (type: exact deny domain)

+ read -r line
+ printf '%s\n\n' 'Found 0 adlists exactly matching '\''gateway.fe.apple-dns.net'\''.'
Found 0 adlists exactly matching 'gateway.fe.apple-dns.net'.

+ '[' 0 -gt 0 ']'
+ DeleteSession
+ '[' '' = true ']'

Even when a bit hard to see, the command succeeded without error this time:

Does it always work when you run

bash -x /opt/pihole/query.sh -q gateway.fe.apple-dns.net

but does not work when you run

bash /opt/pihole/query.sh -q gateway.fe.apple-dns.net

?


Or is it only

pihole -q gateway.fe.apple-dns.net

that fails? Does it fail every time or are there also a few successful calls when you try it, say, five times?

Yes

Works every time.

Tried it 10 times and failed every time.

What is the output of this command?

echo $SHELL

/bin/bash

What's weird is that other domain queries work fine. I think it's only when I use a hostname with apple-dns.net or *.apple-dns.net

Could it be the shebang?

dehakkelaar@ph6b:~$ grep '^#!' /opt/pihole/* | column -t -s :
/opt/pihole/api.sh                  #!/usr/bin/env sh
/opt/pihole/chronometer.sh          #!/usr/bin/env bash
/opt/pihole/gravity.sh              #!/usr/bin/env bash
/opt/pihole/list.sh                 #!/usr/bin/env bash
/opt/pihole/pihole-FTL-poststop.sh  #!/usr/bin/env sh
/opt/pihole/pihole-FTL-prestart.sh  #!/usr/bin/env sh
/opt/pihole/pihole-reenable.sh      #!/bin/bash
/opt/pihole/piholeARPTable.sh       #!/usr/bin/env bash
/opt/pihole/piholeCheckout.sh       #!/usr/bin/env bash
/opt/pihole/piholeDebug.sh          #!/usr/bin/env bash
/opt/pihole/piholeLogFlush.sh       #!/usr/bin/env bash
/opt/pihole/query.sh                #!/usr/bin/env sh
/opt/pihole/uninstall.sh            #!/usr/bin/env bash
/opt/pihole/update.sh               #!/usr/bin/env bash
/opt/pihole/updatecheck.sh          #!/usr/bin/env bash
/opt/pihole/utils.sh                #!/usr/bin/env sh
/opt/pihole/version.sh              #!/usr/bin/env sh
1 Like

I can reproduce the error.

nanopi@nanopi:~$ pihole -q gateway.fe.apple-dns.net
parse error: Invalid escape at line 1, column 224
parse error: Invalid escape at line 1, column 224
Found  domains exactly matching 'gateway.fe.apple-dns.net'.

/opt/pihole/query.sh: 66: [: Illegal number: 
Found  adlists exactly matching 'gateway.fe.apple-dns.net'.

/opt/pihole/query.sh: 79: [: Illegal number:

The issue is the whitelist regex (\.|^)apple-dns\.net$. If it's present, it fails.

1 Like

@deHakkelaar is right. I changed the shebang of query.sh to bash and it works.

1 Like

It fails here:

This is with sh -x /opt/pihole/query.sh ...

+ echo {"search":{"domains":[{"domain":"(\.|^)apple-dns\.net$","type":"allow","kind":"regex","comment":null,"enabled":true,"id":3,"date_added":1701815448,"date_modified":1701815448,"groups":[0]}],"gravity":[],"results":{"domains":{"exact":0,"regex":1},"gravity":{"allow":0,"block":0},"total":1},"parameters":{"N":20,"partial":false,"domain":"gateway.fe.apple-dns.net","debug":false}},"took":0.0026924610137939453}
+ jq .search.domains | [.[] | {domain: .domain, type: .type}]
parse error: Invalid escape at line 1, column 55
+ lists_data=

This is how it looks like with bash -x /opt/pihole/query.sh ...

++ echo '{"search":{"domains":[{"domain":"(\\.|^)apple-dns\\.net$","type":"allow","kind":"regex","comment":null,"enabled":true,"id":3,"date_added":1701815448,"date_modified":1701815448,"groups":[0]}],"gravity":[],"results":{"domains":{"exact":0,"regex":1},"gravity":{"allow":0,"block":0},"total":1},"parameters":{"N":20,"partial":false,"domain":"gateway.fe.apple-dns.net","debug":false}},"took":0.0047924518585205078}'
++ jq '.search.domains | [.[] | {domain: .domain, type: .type}]'
+ lists_data='[
  {
    "domain": "(\\.|^)apple-dns\\.net$",
    "type": "allow"
  }
]'
dehakkelaar@ph6b:~$ readlink -f /usr/bin/sh
/usr/bin/dash
dehakkelaar@ph6b:~$ readlink -f /usr/bin/bash
/usr/bin/bash

Returning the data from

to

somehow removes the backslash escaping

+ echo {"search":{"domains":[{"domain":"(\\.|^)apple-dns\\.net$","type":"allow","kind":"regex","comment":null,"enabled":true,"id":3,"date_added":1701815448,"date_modified":1701815448,"groups":[0]}],"gravity":[],"results":{"domains":{"exact":0,"regex":1},"gravity":{"allow":0,"block":0},"total":1},"parameters":{"N":20,"partial":false,"domain":"gateway.fe.apple-dns.net","debug":false}},"took":0.004665374755859375}
+ data={"search":{"domains":[{"domain":"(\.|^)apple-dns\.net$","type":"allow","kind":"regex","comment":null,"enabled":true,"id":3,"date_added":1701815448,"date_modified":1701815448,"groups":[0]}],"gravity":[],"results":{"domains":{"exact":0,"regex":1},"gravity":{"allow":0,"block":0},"total":1},"parameters":{"N":20,"partial":false,"domain":"gateway.fe.apple-dns.net","debug":false}},"took":0.004665374755859375}

I'll file a PR with the fix

nanopi@nanopi:~$ pihole -q gateway.fe.apple-dns.net
Found 1 domains exactly matching 'gateway.fe.apple-dns.net'.

  - (\.|^)apple-dns\.net$ (type: exact allow domain)

Found 0 adlists exactly matching 'gateway.fe.apple-dns.net'.

Thats nice!
Better have it run with dash instead of bash (performance etc).

@sawsanders

Please try if pihole checkout core fix/escape_FTL_return fixes the issue for you.

pi@pi0-2:~$ pihole -q gateway.fe.apple-dns.net
Found 3 domains exactly matching 'gateway.fe.apple-dns.net'.

  - (\.|^)apple-dns\.net$ (type: exact allow domain)

  - .*;querytype=AAAA (type: exact allow domain)

  - .*;querytype=AAAA;reply=nodata (type: exact deny domain)

Found 0 adlists exactly matching 'gateway.fe.apple-dns.net'.

pi@pi0-2:~$

Works as expected! :+1: