Jump to content

Encode ampersand (&) in URL for "Open URL", and prevent Alfred from encoding it a second time


Recommended Posts

I'm passing a URL to "Open URL" to open. The URL has an ampersand that I want to encode, because otherwise it's treated as part of the URL's query string. However, when I encode it as %26, Alfred encodes that again, therefore making it %2526.

 

How can I stop Alfred from encoding it a second time?

Link to comment
4 hours ago, vitor said:

How are you passing the URL? The Open URL object has checkboxes regarding what it encodes; untick what you don’t need.

 

I've attached a screenshot below. The checkboxes shouldn't matter since I'm using neither placeholder. In any case, I tested by unchecking them, and nothing changed.

Alfred - Open URL.png

Link to comment
Posted (edited)
30 minutes ago, vitor said:

Please provide a short example workflow so I can better understand your issue and how to solve it.

I've attached the test workflow (in the next post)

 

Here are the issues:

 

  • %0A (for a newline) gets added to the end of the URL, when I thought Alfred should trim URLs before opening them.
  • it seems impossible to pass an ampersand as a query string, since Alfred replaces the %26 with %2526

 

As you can see, in the script, I open the URL 

https://example.com/?query=a%26b

But Alfred opens 

https://example.com/?query=a%2526b%0A

instead.

Edited by Gary King
Link to comment

It is the newline which is causing the issue. You can verify this by using a Transform Utility to trim whitespace before passing it to the Open URL, or by appending | tr -d '\n' (which deletes newlines) to the command in the Run Script. You should be able to do the same by having the script not output a newline at the end. With that, the encoding works as expected.

 

I’ll think about it a bit and discuss internally but I’m betting this may be intentional (the Open URL object has existed for a long time). When faced with an entity which has to be encoded (the newline) but isn’t, it makes sense to assume the URL isn’t encoded.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...