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 {...@@ -197,7 +197,12 @@ pub fn percentDecodeInPlace(buffer: []u8) []u8 {
197 return percentDecodeBackwards(buffer, buffer);197 return percentDecodeBackwards(buffer, buffer);
198}198}
199199
200pub const ParseError = error{ UnexpectedCharacter, InvalidFormat, InvalidPort };200pub const ParseError = error{
201 UnexpectedCharacter,
202 InvalidFormat,
203 InvalidPort,
204 InvalidHostName,
205};
201206
202/// Parses the URI or returns an error. This function is not compliant, but is required to parse207/// Parses the URI or returns an error. This function is not compliant, but is required to parse
203/// some forms of URIs in the wild, such as HTTP Location headers.208/// 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...@@ -400,7 +405,7 @@ pub fn resolveInPlace(base: Uri, new_len: usize, aux_buf: *[]u8) ResolveInPlaceE
400 .scheme = new_parsed.scheme,405 .scheme = new_parsed.scheme,
401 .user = new_parsed.user,406 .user = new_parsed.user,
402 .password = new_parsed.password,407 .password = new_parsed.password,
403 .host = try validateHost(new_parsed.host),408 .host = try validateHostComponent(new_parsed.host),
404 .port = new_parsed.port,409 .port = new_parsed.port,
405 .path = remove_dot_segments(new_path),410 .path = remove_dot_segments(new_path),
406 .query = new_parsed.query,411 .query = new_parsed.query,
...@@ -411,7 +416,7 @@ pub fn resolveInPlace(base: Uri, new_len: usize, aux_buf: *[]u8) ResolveInPlaceE...@@ -411,7 +416,7 @@ pub fn resolveInPlace(base: Uri, new_len: usize, aux_buf: *[]u8) ResolveInPlaceE
411 .scheme = base.scheme,416 .scheme = base.scheme,
412 .user = new_parsed.user,417 .user = new_parsed.user,
413 .password = new_parsed.password,418 .password = new_parsed.password,
414 .host = try validateHost(host),419 .host = try validateHostComponent(host),
415 .port = new_parsed.port,420 .port = new_parsed.port,
416 .path = remove_dot_segments(new_path),421 .path = remove_dot_segments(new_path),
417 .query = new_parsed.query,422 .query = new_parsed.query,
...@@ -433,7 +438,7 @@ pub fn resolveInPlace(base: Uri, new_len: usize, aux_buf: *[]u8) ResolveInPlaceE...@@ -433,7 +438,7 @@ pub fn resolveInPlace(base: Uri, new_len: usize, aux_buf: *[]u8) ResolveInPlaceE
433 .scheme = base.scheme,438 .scheme = base.scheme,
434 .user = base.user,439 .user = base.user,
435 .password = base.password,440 .password = base.password,
436 .host = try validateHost(base.host),441 .host = try validateHostComponent(base.host),
437 .port = base.port,442 .port = base.port,
438 .path = path,443 .path = path,
439 .query = query,444 .query = query,
...@@ -441,9 +446,16 @@ pub fn resolveInPlace(base: Uri, new_len: usize, aux_buf: *[]u8) ResolveInPlaceE...@@ -441,9 +446,16 @@ pub fn resolveInPlace(base: Uri, new_len: usize, aux_buf: *[]u8) ResolveInPlaceE
441 };446 };
442}447}
443448
444fn validateHost(bytes: []const u8) HostName.ValidateError![]const u8 {449fn validateHostComponent(optional_component: ?Component) error{InvalidHostName}!?Component {
445 try HostName.validate(bytes);450 const component = optional_component orelse return null;
446 return bytes;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;
447}459}
448460
449/// In-place implementation of RFC 3986, Section 5.2.4.461/// In-place implementation of RFC 3986, Section 5.2.4.
lib/std/http/Client.zig+1
...@@ -1212,6 +1212,7 @@ pub const Request = struct {...@@ -1212,6 +1212,7 @@ pub const Request = struct {
1212 error.UnexpectedCharacter => return error.HttpRedirectLocationInvalid,1212 error.UnexpectedCharacter => return error.HttpRedirectLocationInvalid,
1213 error.InvalidFormat => return error.HttpRedirectLocationInvalid,1213 error.InvalidFormat => return error.HttpRedirectLocationInvalid,
1214 error.InvalidPort => return error.HttpRedirectLocationInvalid,1214 error.InvalidPort => return error.HttpRedirectLocationInvalid,
1215 error.InvalidHostName => return error.HttpRedirectLocationInvalid,
1215 error.NoSpaceLeft => return error.HttpRedirectLocationOversize,1216 error.NoSpaceLeft => return error.HttpRedirectLocationOversize,
1216 };1217 };
12171218