Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
Don't crash on invalid URIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
alcinnz committed Mar 20, 2020
1 parent bc509a3 commit 7ea4fb3
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions src/Services/pages.vala
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,37 @@ namespace Odysseus.Services {
var url = new Data.Mapping(null, url_text);
var parser = new Soup.URI(url_text);

url["fragment"] = new Data.Literal(parser.fragment);
url["host"] = new Data.Literal(parser.host);
url["password"] = new Data.Literal(parser.password);
url["path"] = new Data.Literal(parser.path);
url["port"] = new Data.Literal(parser.port);
url["scheme"] = new Data.Literal(parser.scheme);
url["user"] = new Data.Literal(parser.user);

var q = new Gee.HashMap<Slice, Gee.List<Data.Data>>();
foreach (var keyvalue in parser.query.split("&")) {
var segments = keyvalue.split("=", 2);
if (segments.length == 0) {
warning("Malformed query string '%s'", parser.query);
continue;
}
if (parser != null) {
url["fragment"] = new Data.Literal(parser.fragment);
url["host"] = new Data.Literal(parser.host);
url["password"] = new Data.Literal(parser.password);
url["path"] = new Data.Literal(parser.path);
url["port"] = new Data.Literal(parser.port);
url["scheme"] = new Data.Literal(parser.scheme);
url["user"] = new Data.Literal(parser.user);

var q = new Gee.HashMap<Slice, Gee.List<Data.Data>>();
foreach (var keyvalue in parser.query.split("&")) {
var segments = keyvalue.split("=", 2);
if (segments.length == 0) {
warning("Malformed query string '%s'", parser.query);
continue;
}

var key = new Slice.s(segments[0]);
Data.Data val = new Data.Literal("");
if (segments.length > 1)
val = new Data.Literal(Soup.URI.decode(segments[1].replace("+", " ")));
var key = new Slice.s(segments[0]);
Data.Data val = new Data.Literal("");
if (segments.length > 1)
val = new Data.Literal(Soup.URI.decode(segments[1].replace("+", " ")));

if (!q.has_key(key)) q[key] = new Gee.ArrayList<Data.Data>();
var vals = q[key];
vals.add(val);
}
if (!q.has_key(key)) q[key] = new Gee.ArrayList<Data.Data>();
var vals = q[key];
vals.add(val);
}

var query = new Gee.HashMap<Slice, Data.Data>();
url["query"] = new Data.Mapping(query, parser.query);
foreach (var p in q.entries) query[p.key] = new Data.List(p.value);
var query = new Gee.HashMap<Slice, Data.Data>();
url["query"] = new Data.Mapping(query, parser.query);
foreach (var p in q.entries) query[p.key] = new Data.List(p.value);
}

// Predominantly used by the bad-certificate error page.
if (url_text.has_prefix("https://")) {
Expand Down

0 comments on commit 7ea4fb3

Please sign in to comment.