w3c markup validator ampersand (&) error
Asked Answered
J

4

5

Is there any workaround for the w3c validation error for an & present in urls or some other place in HTML markup?
It says:

& did not start a character reference. (& probably should have been escaped as &.)

The ampersand in my case is a part of a url for gravatar thumbnail. This is the problematic part of a url:

c91588793296e2?s=50&d=http%3A%2F%.

Jaella answered 14/12, 2010 at 16:36 Comment(0)
R
10

for each & sign you got write & in your example it would be:

c91588793296e2?s=50&d=http%3A%2F%
Remount answered 14/12, 2010 at 16:38 Comment(3)
Note that it is not always required to encode ampersands, although it’s probably easiest to just do it. See mathiasbynens.be/notes/ambiguous-ampersands.Rivkarivkah
You can use a regexp detection to automatically add &s where missing: htmlOut = htmlOut.replaceAll("&(?![a-zA-Z]+;)", "&");Thielen
I have a login-with-facebook code that adds a lot of messy not encoded ampersands and creates validation errors. Should I really write code to correct the error of someone else? :/Gaspar
T
9

Use & for literal ampersands, even in URLs.

http://htmlhelp.com/tools/validator/problems.html#amp

Taskwork answered 14/12, 2010 at 16:38 Comment(0)
S
4

Replace with &

Snow answered 14/12, 2010 at 16:38 Comment(0)
B
4

should be:

c91588793296e2?s=50&d=http%3A%2F%.

notice the &

I know it feels wonky, but ampersands have to be encoded as html entities, which are confusingly denoted with ampersands.

Batey answered 14/12, 2010 at 16:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.