fluks / redirect-link

A browser addon to redirect a link to somewhere else.
GNU General Public License v3.0
22 stars 2 forks source link

Add support for RegEx capturing groups #36

Open Clozent opened 1 year ago

Clozent commented 1 year ago

I couldn't notice that I can't use regex capturing groups from the URL to match (the one in the " Enable URL" column) in the URL the extension redirects to.

One way to implement it is by having a toggle that says that the URL (the one in the "URL" column) should be using the RegEx substitution format. Turning on the toggle will make it so the redirect URL won't be able to use the custom formats (such as %p or %u). It will be purely RegEx.

Another way is to have a separate format, like %c[] that will use the RegEx substitution format with capturing groups from the matched URL inside it, although this might cause problems because of the square brackets (I'm not sure, though).

fluks commented 1 year ago

You can use capturing groups in the redirect URL where the match of a capturing group is added into the redirect URL. There's an example in the proposed redirects issue: https://securityscorecard.com/security-rating/%r[(?:https?:\/\/)(?:[^\.\]+\.)?([^\.\/\]+\.[^\.\/\]+)]. Or do you mean using the capturing group match in the regex, for example: %r[aaa(.*)bbb$1]?

Clozent commented 1 year ago

What I meant was using capturing groups from the "Example URL" column of a redirect in the "URL" column of that redirect.

fluks commented 1 year ago

Using capturing group in Enable URL and use that match in URL? I don't understand why would you want that because the Enable URL will be the same as you can match against in URL.

You want this?

Actual URL: abc Enable URL: a(.*)c URL: x.z/$1

But you can do the same with:

Actual URL: abc Enable URL: a.c URL: x.z/%r[a(.)c]

It's a little more work though with current implementation.

Clozent commented 1 year ago

To answer your question of if this is what I want, your example is exactly that. I want to be able to use specific parameters from the actual URL, that were matched by the RegEx in the Enable URL.

fluks commented 1 year ago

Is there a reason you don't want to use the way I showed later in the example? It doesn't work at all or is it too difficult?

Clozent commented 1 year ago

I want this simply because it would be more convenient and straightforward to do in some cases, since you won't need to reuse RegEx. It would also improve clarity (since you can see which part of the URL is used by identifying the capturing group).

fluks commented 4 weeks ago

Now these should work on Chrome with Always redirects. Maybe I will make these work on every scenario.