user822211
user822211

Reputation: 353

"~" turns to "%7E" issue in Sitecore?

Using the Sitecore, I am doing something like customize the URL of the media.
when in PageEditor mode, have you guys ever met "~" turns to "%7E" problem?

for example, check the source of the page in IE(or chrome, firefox), i was expecting something like,

<img src="~/media/twitter.gif" alt="Twitter" width="100" height="22" />

but came up this,

<img src="%7E/media/twitter.gif" alt="Twitter" width="100" height="22" />

I have checked my code, i don't think i did something which would change the '~' to '%7E', Have ever met something like this, if you have, please let me know, and how i can solve it.Thanks

Upvotes: 1

Views: 4062

Answers (3)

James Walford
James Walford

Reputation: 2953

As has been previously answered, %7E is the URL encoding of the ~ symbol.

We have had a similar problem when copy-pasting links in the rich text editor. Broadly speaking, what seems to be happening is that when copying the HTML output of the rich text editor we are already working in a browser, which is rendering the HTML source. Links, for example, are being resolved by the browser (so that if an author is logged into Sitecore to edit for one particular host domain but works on a different host domain the links resolve to the domain they are logged in for).

We have had the specific %7E replacing ~ problem when doing this as well.

You don't quite give enough details for me to be sure this is what is happening in your case, but it seems fairly likely. If you're copy-pasting browser rendered HTML then you aren't accessing the raw strings.

EDIT: This is probably related to a known Sitecore bug with adding path information for the rich text editor to a link when copy pasting. Sitecore have a fix for it here:

http://sdn.sitecore.net/Products/Sitecore%20V5/Sitecore%20CMS%206/ReleaseNotes/KnownIssues%20Recommended/Copying%20and%20pasting%20link%20in%20rt%20fields%20may%20break%20the%20link.aspx

Upvotes: 1

Anthony
Anthony

Reputation: 37065

~ is a shortcut to access your home directory (or, if passed to an app running under a different user, that user's home directory. So generally it's not kosher to lead a URL with ~.

On the other hand, the browser will resolve URL encoded chunks to their equivalent, as long as it's not in the query string. For instance:

http://en.wikipedia.org/wiki/Sir%20Mix-a-Lot

Will resolve to:

http://en.wikipedia.org/wiki/Sir Mix-a-Lot

(which mediawiki further resolves to:

http://en.wikipedia.org/wiki/Sir_Mix-a-Lot

But if you are trying to access a file path outside of the webroot, you're likely to get errors, especially client-side. And if you don't you're likely to get a talkin to if you get caught.

Upvotes: 1

Trott
Trott

Reputation: 70075

%7E is the URL encoding for ~. The HTML using the encoded value is totally fine.

If you are trying to use ~ to get to the user's home directory (which I suspect you are), don't do that. Learn about web docroot, and relative and absolute paths, then figure out what the actual path you want to use would be.

Upvotes: 3

Related Questions