-
Notifications
You must be signed in to change notification settings - Fork 269
Add support for regular expressions in $app
modifier
#714
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
base: master
Are you sure you want to change the base?
Conversation
Add support for regular expressions in `$app` modifier
add mix
updated based on comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 To request another review, post a new comment with "/windsurf-review".
@@ -1939,7 +1967,7 @@ In AdGuard for Windows, Mac and Android with [CoreLibs] v1.11 or later, JSONPath | |||
{ | |||
"elems": [ | |||
{ | |||
"a": {"b": {"c": 123}}, | |||
"a": {"b": {"c": 123}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comma at the end of line 1970 was removed, but this would make the JSON example invalid. JSON requires commas between array/object elements.
You can use regular expressions in the `$app` modifier by enclosing them in forward slashes `/.../`. This allows for more flexible matching — for example, targeting a group of apps from the same publisher or matching complex patterns. | ||
|
||
- `||baddomain.com^$app=/org\.example\.[a-z0-9_]+/` — applies to all apps whose package name starts with `org.example` (e.g. `org.example.app1`, `org.example.utility`, etc.). | ||
- `||baddomain.com^$app=/^org\.example\.app\$\|^org\.example\.[ab].*/` — applies to `org.example.app` and to any app whose package starts with `org.example.a` or `org.example.b`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This regular expression example is quite complex with double escaping. Consider adding a simpler example first before showing this more advanced pattern, or adding a comment explaining the escaping requirements (e.g., why \.
is needed instead of just .
).
@@ -425,6 +425,19 @@ This modifier lets you narrow the rule coverage down to a specific application ( | |||
|
|||
For Mac, you can find out the bundle ID or the process name of the app by viewing the respective request details in the Filtering log. | |||
|
|||
**Syntax** | |||
|
|||
The modifier is a list of one or more expressions separated by the `|` symbol, each of which is matched against a application in a particular way depending on its type (see below). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The modifier is a list of one or more expressions separated by the `|` symbol, each of which is matched against a application in a particular way depending on its type (see below). | |
The modifier is a list of one or more expressions, each of which is matched against an application in a particular way depending on its type. These expressions are separated by the `|` symbol. |
entry_i = ( regular_app / wildcard_app / regexp ) | ||
``` | ||
|
||
- **`regular_app`** — a regular application name (`example.app`). Corresponds the specified application and its subapplications. It is matched lexicographically. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- **`regular_app`** — a regular application name (`example.app`). Corresponds the specified application and its subapplications. It is matched lexicographically. | |
- **`regular_app`** — a regular application name (`example.app`). It corresponds to the specified application and its subapplications and is matched lexicographically. |
|
||
- **`regular_app`** — a regular application name (`example.app`). Corresponds the specified application and its subapplications. It is matched lexicographically. | ||
- **`wildcard_app`** — an application name ending with a wildcard character `*`, such as `org.example.*` or `com.ad*`. It matches all applications whose names start with the specified prefix. Matching is done lexicographically. | ||
- **`regexp`** — a regular expression, starts and ends with `/`. The pattern works the same way as in the basic URL rules, but the characters `/`, `$`, `,`, and `|` must be escaped with `\`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- **`regexp`** — a regular expression, starts and ends with `/`. The pattern works the same way as in the basic URL rules, but the characters `/`, `$`, `,`, and `|` must be escaped with `\`. | |
- **`regexp`** — a regular expression that starts and ends with `/`. It works the same way as the basic URL rules, but the characters `/`, `$`, `,`, and `|` must be escaped with `\`. |
@@ -435,17 +448,32 @@ If you want the rule not to be applied to certain apps, start the app name with | |||
- `||baddomain.com^$app=~org.example.app` — a rule to block requests that match the specified mask and are sent from any app except for the `org.example.app`. | |||
- `||baddomain.com^$app=~org.example.app1|~org.example.app2` — same as above, but now two apps are excluded: `org.example.app1` and `org.example.app2`. | |||
|
|||
You can use wildcards in the $app modifier: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use wildcards in the $app modifier: | |
You can use wildcards in the `$app` modifier: |
|
||
The `$app` modifier supports combining all three types of entries — plain names, wildcards, and regular expressions — within the same rule, but it does not allow combining negated and non-negated expressions together. | ||
|
||
- `||example.com^$app=org.example.app|org.example.*|/org\.example\.[a-z]+/` — applies to `org.example.app`, all matching `org.example.*` and all matching `org.example.[a-z]+` apps. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `||example.com^$app=org.example.app|org.example.*|/org\.example\.[a-z]+/` — applies to `org.example.app`, all matching `org.example.*` and all matching `org.example.[a-z]+` apps. | |
- `||example.com^$app=org.example.app|org.example.*|/org\.example\.[a-z]+/` — applies to `org.example.app`, all matching `org.example.*` and `org.example.[a-z]+` apps. |
Apps in the modifier value cannot have a wildcard, e.g. `$app=com.*.music`. | ||
Rules with such modifier are considered invalid. | ||
- Apps in the modifier value cannot include a wildcard inside the string , e.g. `$app=com.*.music`. | ||
Use a regular expression instead: `$app=/com\..*\.music/` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a regular expression instead: `$app=/com\..*\.music/` | |
Use a regular expression instead: `$app=/com\..*\.music/`. |
|
||
::: | ||
|
||
:::info Compatibility | ||
|
||
- Only AdGuard for Windows, Mac, Android are technically capable of using rules with `$app` modifier. | ||
- On Windows the process name is case-insensitive starting with AdGuard for Windows with [CoreLibs] v1.12 or later. | ||
- Support for regular expressions and combined formats in `$app` is available starting from CoreLibs v1.19 or later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does combined formats
mean? it cannot be searched on the page. i.e. it looks like you are introducing a new term here
This PR updates the
$app
modifier documentation to include support for regular expressionsAdguardTeam/CoreLibs#1906