authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-09 16:30:27-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:49-07:00
log9e681cab56eb306f3e5ba88a951625408f72f696
tree36f63285886a16be91f2c80a94fd6bf8936ef069
parent63801c4b058feae3a9b6ca2bbe8effeae267abbc

std.Uri: fix compilation error


2 files changed, 20 insertions(+), 7 deletions(-)

lib/std/Uri.zig+19-7
......@@ -197,7 +197,12 @@ pub fn percentDecodeInPlace(buffer: []u8) []u8 {
197197 return percentDecodeBackwards(buffer, buffer);
198198}
199199
200pub const ParseError = error{ UnexpectedCharacter, InvalidFormat, InvalidPort };
200pub const ParseError = error{
201 UnexpectedCharacter,
202 InvalidFormat,
203 InvalidPort,
204 InvalidHostName,
205};
201206
202207/// Parses the URI or returns an error. This function is not compliant, but is required to parse
203208/// some forms of URIs in the wild, such as HTTP Location headers.
......@@ -400,7 +405,7 @@ pub fn resolveInPlace(base: Uri, new_len: usize, aux_buf: *[]u8) ResolveInPlaceE
400405 .scheme = new_parsed.scheme,
401406 .user = new_parsed.user,
402407 .password = new_parsed.password,
403 .host = try validateHost(new_parsed.host),
408 .host = try validateHostComponent(new_parsed.host),
404409 .port = new_parsed.port,
405410 .path = remove_dot_segments(new_path),
406411 .query = new_parsed.query,
......@@ -411,7 +416,7 @@ pub fn resolveInPlace(base: Uri, new_len: usize, aux_buf: *[]u8) ResolveInPlaceE
411416 .scheme = base.scheme,
412417 .user = new_parsed.user,
413418 .password = new_parsed.password,
414 .host = try validateHost(host),
419 .host = try validateHostComponent(host),
415420 .port = new_parsed.port,
416421 .path = remove_dot_segments(new_path),
417422 .query = new_parsed.query,
......@@ -433,7 +438,7 @@ pub fn resolveInPlace(base: Uri, new_len: usize, aux_buf: *[]u8) ResolveInPlaceE
433438 .scheme = base.scheme,
434439 .user = base.user,
435440 .password = base.password,
436 .host = try validateHost(base.host),
441 .host = try validateHostComponent(base.host),
437442 .port = base.port,
438443 .path = path,
439444 .query = query,
......@@ -441,9 +446,16 @@ pub fn resolveInPlace(base: Uri, new_len: usize, aux_buf: *[]u8) ResolveInPlaceE
441446 };
442447}
443448
444fn validateHost(bytes: []const u8) HostName.ValidateError![]const u8 {
445 try HostName.validate(bytes);
446 return bytes;
449fn validateHostComponent(optional_component: ?Component) error{InvalidHostName}!?Component {
450 const component = optional_component orelse return null;
451 switch (component) {
452 .raw => |raw| HostName.validate(raw) catch return error.InvalidHostName,
453 .percent_encoded => |encoded| {
454 // TODO validate decoded name instead
455 HostName.validate(encoded) catch return error.InvalidHostName;
456 },
457 }
458 return component;
447459}
448460
449461/// In-place implementation of RFC 3986, Section 5.2.4.
lib/std/http/Client.zig+1
......@@ -1212,6 +1212,7 @@ pub const Request = struct {
12121212 error.UnexpectedCharacter => return error.HttpRedirectLocationInvalid,
12131213 error.InvalidFormat => return error.HttpRedirectLocationInvalid,
12141214 error.InvalidPort => return error.HttpRedirectLocationInvalid,
1215 error.InvalidHostName => return error.HttpRedirectLocationInvalid,
12151216 error.NoSpaceLeft => return error.HttpRedirectLocationOversize,
12161217 };
12171218