diff options
author | Bastien Nocera <hadess@hadess.net> | 2019-11-06 16:01:29 +0000 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2019-11-06 16:01:29 +0000 |
commit | a23068c3f0aa97a51eb60dcdb804f382e532a761 (patch) | |
tree | 38b10e3e75e90cbad7c584de0c580af93f1c69f0 | |
parent | d79678ecd28cc9543f90848a62174b84cead880c (diff) | |
parent | 5f31b1c70e0609cd5313d5bad5873048e5cecfe9 (diff) | |
download | geocode-glib-a23068c3f0aa97a51eb60dcdb804f382e532a761.tar.gz |
Merge branch 'wip/issue-18' into 'master'
location: Allow unknown parameters inside geo: URL
See merge request GNOME/geocode-glib!11
-rw-r--r-- | geocode-glib/geocode-location.c | 40 | ||||
-rw-r--r-- | geocode-glib/tests/geo-uri.c | 3 |
2 files changed, 21 insertions, 22 deletions
diff --git a/geocode-glib/geocode-location.c b/geocode-glib/geocode-location.c index debe27b..70a94c1 100644 --- a/geocode-glib/geocode-location.c +++ b/geocode-glib/geocode-location.c @@ -337,42 +337,38 @@ parse_geo_uri_parameters (GeocodeLocation *loc, char *val; char *u = NULL; char *crs = NULL; + int i; int ret = TRUE; - parameters = g_strsplit (params, ";", 2); + parameters = g_strsplit (params, ";", 256); if (parameters[0] == NULL) goto err; - if (g_str_has_prefix (parameters[0], "u=")) { - /* - * if u parameter is first, then there should not be any more - * parameters. - */ - if (parameters[1] != NULL) - goto err; - - u = parameters[0]; - } else if (g_str_has_prefix (parameters[0], "crs=")) { - /* - * if crs parameter is first, then the next should be the u - * parameter or none. - */ - crs = parameters[0]; - if (parameters[1] != NULL){ + for (i = 0; parameters[i] != NULL; i++) { + if (g_str_has_prefix (parameters[i], "crs=")) { + /* + * if crs parameter is given, it has to be the first one + */ + if (i != 0) + goto err; - if (!g_str_has_prefix (parameters[1], "u=")) + crs = parameters[i]; + } else if (g_str_has_prefix (parameters[i], "u=")) { + /* + * u parameter is either first one or after crs parameter and + * has to appear only once in the parameter list + */ + if ((crs == NULL && i != 0) || (crs != NULL && i != 1) || u != NULL) goto err; - u = parameters[1]; + u = parameters[i]; } - } else { - goto err; } if (u != NULL) { val = u + 2; /* len of 'u=' */ loc->priv->accuracy = g_ascii_strtod (val, &endptr); - if (*endptr != '\0') + if (*endptr != '\0' && *endptr != ';') goto err; } diff --git a/geocode-glib/tests/geo-uri.c b/geocode-glib/tests/geo-uri.c index 4bd50de..082e1ab 100644 --- a/geocode-glib/tests/geo-uri.c +++ b/geocode-glib/tests/geo-uri.c @@ -42,6 +42,9 @@ static struct uri uris[] = { { "geo:13.37,42.42;u=45.5", TRUE }, { "geo:13.37,42.42,12.12;u=45.5", TRUE }, { "geo:13.37,42.42,12.12;crs=wgs84;u=45.5", TRUE }, + { "geo:13.37,42.42,12.12;crs=wgs84;u=45.5;u=10", FALSE }, + { "geo:13.37,42.42,12.12;crs=wgs84;u=45.5;crs=wgs84", FALSE }, + { "geo:13.37,42.42,12.12;crs=wgs84;u=45.5;z=18", TRUE }, { "geo:0.0,0,0", TRUE }, { "geo :0.0,0,0", FALSE }, { "geo:0.0 ,0,0", FALSE }, |