So many times when I copy a link in Safari, it will swap spaces or dashes with this code (%2D). It also does it when I type in a search query and hit return. Naturally, I don’t get results. Is there a setting I need to look at to keep this from happening? Really annoying!
Spaces have to be encoded as %20 in URLs. URLs cannot contain spaces as such. This should not affect your search results though.
I have a web site for my law firm where the words are separated by dashes. When I get links for the pages, Safari encodes the dashes as #2D, instead of keeping the dashes.
Also, although it can’t use spaces in URLs, it refuses to use them in search queries, thus screwing that up. Looking to see if I can fix that.
A hyphen is a “safe” character and does not require encoding in the HTML representation of text. (See link below.)
(Please) Stop Using Unsafe Characters in URLs | Perishable Press
I grab URLs containing hyphens all the time and Safari does NOT encode them as %2D (“2D” is simply the hexadecimal code you find in an ASCII character chart for the hyphen character.)
That only leaves something in your website software to blame for the encoding.
Where are you getting the links? The address bar? Right-clicking a URL on a page? What’s the flow here?
I get it when I click on a web site link and when I right click on it to copy the link.
What you are describing is extremely odd behavior, and I suspect it’s not Safari’s fault. Is your website public? Can you share the URL? Does the behavior persist if you use a different browser? I’m perplexed and curious.
Okay, then what are you trying to DO with the link where it’s not working? Just paste it into Safari, or something else?
I’m thinking that you’re running into a bug of some sort, as %2D is a hyphen, and %20 is a space. Both are perfectly-legal characters in URLs, so they shouldn’t be causing a problem. For example, you can replace all the dashes in this topic’s title with %2D and this topic can be linked to as:
https://talk.macpowerusers.com/t/how%2Ddo%2Di%2Dkeep%2Dsafari%2Dfrom%2Dreplacing%2Da%2Dspace%2Dor%2Da%2Ddash%2Dwith%2D2d/33463
It’s godawfully ugly, but it’s not invalid syntax.
It’s not Safari’s fault.
If we’re talking about the website in your profile, some links copy properly with dashes (whether you right-click the link and copy, or copy from the address bar).
Other links (e.g. those on the Case Results page) copy with dashes replaced by the %2D code because, if you look at the HTML source of that particular page, that’s how they are linked from there in the HTML source. How that came to be and why, I don’t know. I’d ask the folks who did your website. Which CMS are you using?
Web site is public at www.richardsonlawoffices.com. Problem not there in Chrome, which is why I suspected Safari. Also happens on more than one machine using Safari.
Ah, I see what you are talking about now. You are referring to links that look like this, right?
https://www.richardsonlawoffices.com/case_results/how%2Da%2Dfield%2Dsobriety%2Dtest%2Dbeat%2Da%2Dnj%2Ddui%2Dcharge%2Ecfm
It’s ugly, but apparently it’s what your website accepts because the links work. Our suspicion was correct that it’s not Safari’s fault, and another browser wouldn’t matter either. So, if you want cleaner URLs, you’ll have to reconfigure the website.
I get the same links in Firefox:
https://www.richardsonlawoffices.com/case_results/bank%2Dlevy%2Dlifted%2Dwhen%2Dcreditor%2Dfroze%2Dmoney%2Dof%2Ddebtor%2Ds%2Dspouse%2Ecfm
My web site provider uses a proprietary platform based on the Cold Fusion language. I will reach out to them I will also test it on other web sites to see if it persists there. I have only ever noticed it on my site.
However, what you state does not explain why Safari replaces spaces with %20 when I type a search query into the URL bar. That looks to be Safari’s fault.
That may be me creating links to other pages. I copy the link and then paste it into the page I am creating. The link includes the %2D codes. This isn’t how the CMS generates the links.
Any browser will replace spaces with %20 when sending the search query to Google or any other search engine because it is not allowed to send actual spaces in the URL.
Ah, that’s correct, but that’s just how URLs work. URLs can’t have spaces, so they are replaced with %20
by default. That’s going to be the same across all search platforms. BUT… (I think I’m starting to get it) if what you are saying is you type a search term into Safari, and it’s replaced by a URL when you go to copy it, BUT in Chrome you can copy the words that you searched for and not the URL, that makes perfect sense.
Unfortunately, I’m not sure there’s a way around that. I don’t use Chrome so I can’t verify this, but that’s my current theory.
Sure it can. I just typed “search for anything” into Safari and got results. This doesn’t always happen, however, and Safari will change it to “search%20for%20anything” and Google will have a hissy.
Ah! I just tried this in Safari and I see what’s happening. Safari hides the URL from you, and shows you the search term, but when you go to copy it instead of the search terms that it is currently showing you, it copies the URL instead. It’s trying to be clever, but winds up being too clever by half.
I can 100% see how that can be frustrating and confusing behavior. Not great UX design, honestly.
But to answer your original question… I don’t know how to change that. Maybe by copying the text from the search box in google.com instead of the URL bar in Safari?