Why does Google not support valid URLs with & in query string?
Asked Answered
H

1

3

Trying to validate the following HTML with the W3C validator will throw 3 errors (as of 2013-10-30):

<!DOCTYPE html>
<head><title>asdf</title></head>
<img src="http://maps.googleapis.com/maps/api/staticmap?zoom=13&size=279x183&markers=50.916780,5.347420&sensor=false" alt="map">

The 3 errors are all the same:

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

Unfortunately, conforming to the W3C here will lead to the static maps image not being rendered. Try to embed an img tag with the following URL as the value for its src attribute:

<img src="http://maps.googleapis.com/maps/api/staticmap?zoom=13&amp;size=279x183&amp;markers=50.916780,5.347420&amp;sensor=false">

This returns an error by Google stating:

The Google Maps API server rejected your request. Invalid request. Missing the 'size' parameter.

Why does the Google Static Maps API not support valid URLs with &amp; in query string?

Hesychast answered 30/10, 2013 at 9:49 Comment(0)
C
2

You escaped the & characters correctly.

Note that you can’t enter the URI with escaped ampersands directly into the address bar of your browser. It only works if used in HTML (i.e. in href and src attributes).

The URL in question works perfectly as link (and also as image).


Note that you probably don’t have to escape these ampersands (as they seem to be unambiguous); but to be always on the safe side, simply escape them all.

Commonality answered 2/11, 2013 at 3:7 Comment(1)
Looks like Google now supports the escaped & characters in the img src attribute.Hesychast

© 2022 - 2024 — McMap. All rights reserved.