1

I am using Firefox 119.0 (64-bit) on Fedora 38. I would like to be able to copy a links that contain parenthesis to clipboard from the address bar with them as encoded. For example, when copying the URL:

https://en.wikipedia.org/wiki/The_Martian_(film)

I would like it to be copied to the clipboard as:

https://en.wikipedia.org/wiki/The_Martian_%28film%29

Mostly, I would like this capability because reddit's markdown processor is too freaking stupid to correctly process the markdown of something like [The Martian](https://en.wikipedia.org/wiki/The_Martian_(film)) and will instead link to https://en.wikipedia.org/wiki/The_Martian_(film (missing closing paren) and display an extra closing parenthesis as text... despite the fact that superuser/stackexchange, lemmy, and github all manage to handle this scenario correctly without this issue.

At first, I thought maybe I could use browser.urlbar.decodeURLsOnCopy=false to accomplish this. But then I saw this value is already false by default (at least on Fedora). After looking into this issue somewhat more, I believe the reason it does not behave the way I would like it to is that parenthesis are not considered as something that need to ever be escaped - I suspect per some W3C spec as encodeURIComponent completely ignores this character.

Leaving aside the wisdom of continuing to even bother with reddit... My question is: is there some other way to achieve this goal of copying encoded parenthesis to clipboard, e.g. via some other about:config property or via some existing addon? Or is this a lost cause and my time would be better spent writing a userscript to fix this behavior on the reddit side before posting?

1 Answer 1

1

Partial(?) answer:

$ alias |  grep url
alias urldecode='python3 -c "import sys; from urllib.parse import unquote; print(unquote(sys.argv[1]))"'
alias urlencode='python3 -c "import sys; from urllib.parse import quote; print(quote(sys.argv[1]))"'

$ urlencode "https://en.wikipedia.org/wiki/The_Martian_(film)"
https%3A//en.wikipedia.org/wiki/The_Martian_%28film%29

... as you can see, it replaces the : too (with %3A), so might not be exactly what you want.


Combine with this bash script:

$ cat $(which clipb)
#!/bin/bash
#
# Usage: someapp | clipboard     # Pipe someapp's output into clipboard
#        clipboard | someapp     # Pipe clipboard's content into someapp
#

if command -v xclip 1>/dev/null; then
    if [[ -p /dev/stdin ]] ; then
        # stdin is a pipe
        # stdin -> clipboard
        xclip -i -selection clipboard
    else
        # stdin is not a pipe
        # clipboard -> stdout
        xclip -o -selection clipboard
    fi
else
    echo "Remember to install xclip"
fi

Works on Ubuntu 20.04, no guarantees for newer or other

3
  • I do appreciate you trying but I should have clarified that I was looking for a purely in-browser way of accomplishing this... Not trying to be nitpicky, I am not opposed to using bash - in fact, I already have a way to do this using a bash shell function which simply replaces the parenthesis characters. The xclip part was especially interesting
    – zpangwin
    Nov 16, 2023 at 18:43
  • The problem is that I run ff within a firejail container so trying to handle things externally, I either need to sacrifice security (e.g. stop running browser in a sandbox / make exceptions that could be bad if ever my browser was compromised), use a different sandboxing system which I prefer not to due to customizations I already have in place (e.g. keepassxc browser integration), or wade thru a lot of extra complexity to solve for firejail (if it's even possible)
    – zpangwin
    Nov 16, 2023 at 18:44
  • I apologize as I now realize that I should have stated the firejail component in my original post (I had originally thought adding that would complicate the question even more than it was already). I will mark this as accepted since it would work under the original ask. But I guess from the lack of any in-browser solutions and nobody else interested in this question that I should just give up hope on any built-in or existing solutions that would work entirely in-browser (e.g. with firejail) and look into the possibility of writing an addon or userscript to solve this.
    – zpangwin
    Nov 16, 2023 at 18:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .