HTML GET with & in a parameter - html

I fured out, that I got a problem with the "&" in a parameter, because the browser is interpreting it as a new parameter. Using urlencode doesn't help.
Example: http://www.example.com?artist=Brooks & Dunn&title=Maria
Is there a way to go around that problem?

Use URL encoding to encode unsafe characters in an URL.
http://www.example.com?artist=Brooks%20%26%20Dunn&title=Maria
See https://en.wikipedia.org/wiki/Percent-encoding

Related

html URL: '%23' not converted to #

A webpage is opened if the URL contains '#'. But i get 'Page Not Found' error if the url contains '%23' instead of #.
Few months earlier, i was able to access my html page using the following link '%23'.
https://www.something.com/index.html%23MyPage
however, these links are now not working. but works if %23 is changed to #.
https://www.something.com/index.html#MyPage
curious, what could be the reason. Could it be something changed in the webserver? I have such links specified in many places and do not want to change if possible.
Will appreciate your help.
Using %23 instead of # is not possible. The whole purpose of URL encoded strings is that they should not have any function in the URL itself, so that you can pass letters to the URL which normally have functions.
For example ? / #. If these characters aren't encoded, the URL wants to treat them according to their function. So what if you want to use one of these characters without their function? You use encoded characters which will have no functions and are simply treated as strings.

HTML Hrefs in Tomcat

I'm building a HTML string in tomcat and I notice that in my JSON object, my clickable href link is something like:
http://localhost/%22/https://myLinkHere.com/%22
This is a 2 part question. First, should it contain the http://localhost in front? And secondly, why is the %22 there?
Here is what my JSON href looks like in text:
linkDisplayName
This looks right to me, but I can't tell why the last %22 is there.
I think you won't need the localhost as long as you are supplying the relative path
The ascii code for %22 is " which is correctly referenced in your link.
HTML parsers are very lenient, which often leads to confusing behavior. Without the exact JSON it's hard to say for sure but there are a couple of obvious issues. Ultimately the issue is your HTML is malformed and/or mis-escaped.
%22 is " URL-encoded, which means that the quotes you've \-escaped are being included in the URL rather than surrounding them. That likely means that in the JSON they're double-escaped. That might mean it's \\" or something similar; try just a single backslash (\") or no backslash at all (").
Notice that the protocol (https:/) in your URL is also wrong; a URL starts with a protocol (like https) followed by a :, and generally followed by two slashes (//). Your URL follows the protocol with just a single slash, which makes it look like a relative URL rather than an absolute one. Browsers will prefix relative URLs with whatever they infer the current host to be, which in your context appears to be localhost.
The HTML should look like this:
linkDisplayName
So in summary no, the URL should probably not contain http://localhost, and it should not contain those %22s either. They're showing up because your JSON is malformed.

Anchor link to app with parameters, google apps script

I have the following anchors in my html template:
<button>All Feedback</button>
<button>Bomgar Feedback</button>
<button>Ticket Feedback</button>
When navigating to the links with parameters, the "&" and "=" symbols are %26 and %3d in the url. Is there a way to prevent this from happening ?
Thanks
To add GET parameters to a URL, you should use the ? character to introduce them (instead of the & character). The ampersand is used to add multiple variables. So your URL should look like this.
http://script.google.com/[.......]/exec?variable=data&otherVariable=otherData
So since you didn't have the ?, the URL was sanitized to eliminate those characters.
This web app that I made illustrates the difference.
<button>Bomgar Feedback</button>

What other characters beside ampersand (&) should be encoded in HTML href/src attributes?

Is the ampersand the only character that should be encoded in an HTML attribute?
It's well known that this won't pass validation:
Because the ampersand should be &. Here's a direct link to the validation fail.
This guy lists a bunch of characters that should be encoded, but he's wrong. If you encode the first "/" in http:// the href won't work.
In ASP.NET, is there a helper method already built to handle this? Stuff like Server.UrlEncode and HtmlEncode obviously don't work - those are for different purposes.
I can build my own simple extension method (like .ToAttributeView()) which does a simple string replace.
Other than standard URI encoding of the values, & is the only character related to HTML entities that you have to worry about simply because this is the character that begins every HTML entity. Take for example the following URL:
http://query.com/?q=foo&lt=bar&gt=baz
Even though there aren't trailing semi-colons, since < is the entity for < and > is the entity for >, some old browsers would translate this URL to:
http://query.com/?q=foo<=bar>=baz
So you need to specify & as & to prevent this from occurring for links within an HTML parsed document.
The purpose of escaping characters is so that they won't be processed as arguments. So you actually don't want to encode the entire url, just the values you are passing via the querystring. For example:
http://example.com/?parameter1=<ENCODED VALUE>&parameter2=<ENCODED VALUE>
The url you showed is actually a perfectly valid url that will pass validation. However, the browser will interpret the & symbols as a break between parameters in the querystring. So your querystring:
?q=whatever&lang=en
Will actually be translated by the recipient as two parameters:
q = "whatever"
lang = "en"
For your url to work you just need to ensure that your values are being encoded:
?q=<ENCODED VALUE>&lang=<ENCODED VALUE>
Edit: The common problems page from the W3C you linked to is talking about edge cases when urls are rendered in html and the & is followed by text that could be interpreted as an entity reference (&copy for example). Here is a test in jsfiddle showing the url:
http://jsfiddle.net/YjPHA/1/
In Chrome and FireFox the links works correctly, but IE renders &copy as ©, breaking the link. I have to admit I've never had a problem with this in the wild (it would only affect those entity references which don't require a semicolon, which is a pretty small subset).
To ensure you're safe from this bug you can HTML encode any of your URLS you render to the page and you should be fine. If you're using ASP.NET the HttpUtility.HtmlEncode method should work just fine.
You do not need HTML escapement here:
According to the HTML5 spec:
http://www.w3.org/TR/html5/tokenization.html#character-reference-in-attribute-value-state
&lang= should be parsed as non-recognized character reference and value of the attribute should be used as it is: http://domain.com/search?q=whatever&lang=en
For the reference: added question to HTML5 WG: http://lists.w3.org/Archives/Public/public-html/2011Sep/0163.html
In HTML attribute values, if you want ", '&' and a non-breaking space as a result, you should (as an author who is clear about intent) have ", & and in the markup.
For " though, you don't have to use " if you use single quotes to encase your attribute values.
For HTML text nodes, in addition to the above, if you want < and > as a result, you should use < and >. (I'd even use these in attribute values too.)
For hfnames and hfvalues (and directory names in the path) for URIs, I'd used Javascript's encodeURIComponent() (on a utf-8 page when encoding for use on a utf-8 page).
If I understand the question correctly, I believe this is what you want.

Some Apostrophes showing as â?T in HTML Emails

I'm using ASP Classic/VBScript to send emails using CDO.Message object. It appears that the single quote or apostrophe character ’ (as opposed to the standard character ') shows up in the recipients email as: â?T
Where is the problem and what is the best way to resolve this? I actually tried running a replace to change all ’ to ' but it appears that didn't work.
I guess I'm really not even sure what the difference is between these two different characters, and why some sites, like Microsoft for example, use ’.
http://www.hanselman.com/blog/WhyTheAskObamaTweetWasGarbledOnScreenKnowYourUTF8UnicodeASCIIAndANSIDecodingMrPresident.aspx
all the info you could need on character encoding.
You need to set the correct character encoding on .BodyPart.Charset of your CDO.Message object.
Most likely you need to set it to "utf-8" as the default appears to be "us-ascii".
This indeed was a problem of character encoding. The solution was to put two lines of code in the web page that contains my form. I actually opted to add these lines of code to the top of my Global include file which I named inc_globals.asp. This file appears at the top of every page. Here's the code that fixed the problem:
Response.CodePage = 65001
Response.CharSet = "utf-8"
As a matter of documentation, here's a post that was helpful in solving this case:
http://groups.google.com/group/microsoft.public.inetserver.asp.general/browse_thread/thread/b79e6b95e24ef0fe/a25c643aaf12770d
Mails are written in HTML format. Have you tried using HTML Entities? For your apostrophe, it should be '.
In VB :
Replace mailBody, "'", "'"