| ... | ... | @@ -197,7 +197,12 @@ pub fn percentDecodeInPlace(buffer: []u8) []u8 { |
| 197 | 197 | return percentDecodeBackwards(buffer, buffer); |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | | pub const ParseError = error{ UnexpectedCharacter, InvalidFormat, InvalidPort }; |
| 200 | pub const ParseError = error{ |
| 201 | UnexpectedCharacter, |
| 202 | InvalidFormat, |
| 203 | InvalidPort, |
| 204 | InvalidHostName, |
| 205 | }; |
| 201 | 206 | |
| 202 | 207 | /// Parses the URI or returns an error. This function is not compliant, but is required to parse |
| 203 | 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 | 405 | .scheme = new_parsed.scheme, |
| 401 | 406 | .user = new_parsed.user, |
| 402 | 407 | .password = new_parsed.password, |
| 403 | | .host = try validateHost(new_parsed.host), |
| 408 | .host = try validateHostComponent(new_parsed.host), |
| 404 | 409 | .port = new_parsed.port, |
| 405 | 410 | .path = remove_dot_segments(new_path), |
| 406 | 411 | .query = new_parsed.query, |
| ... | ... | @@ -411,7 +416,7 @@ pub fn resolveInPlace(base: Uri, new_len: usize, aux_buf: *[]u8) ResolveInPlaceE |
| 411 | 416 | .scheme = base.scheme, |
| 412 | 417 | .user = new_parsed.user, |
| 413 | 418 | .password = new_parsed.password, |
| 414 | | .host = try validateHost(host), |
| 419 | .host = try validateHostComponent(host), |
| 415 | 420 | .port = new_parsed.port, |
| 416 | 421 | .path = remove_dot_segments(new_path), |
| 417 | 422 | .query = new_parsed.query, |
| ... | ... | @@ -433,7 +438,7 @@ pub fn resolveInPlace(base: Uri, new_len: usize, aux_buf: *[]u8) ResolveInPlaceE |
| 433 | 438 | .scheme = base.scheme, |
| 434 | 439 | .user = base.user, |
| 435 | 440 | .password = base.password, |
| 436 | | .host = try validateHost(base.host), |
| 441 | .host = try validateHostComponent(base.host), |
| 437 | 442 | .port = base.port, |
| 438 | 443 | .path = path, |
| 439 | 444 | .query = query, |
| ... | ... | @@ -441,9 +446,16 @@ pub fn resolveInPlace(base: Uri, new_len: usize, aux_buf: *[]u8) ResolveInPlaceE |
| 441 | 446 | }; |
| 442 | 447 | } |
| 443 | 448 | |
| 444 | | fn validateHost(bytes: []const u8) HostName.ValidateError![]const u8 { |
| 445 | | try HostName.validate(bytes); |
| 446 | | return bytes; |
| 449 | fn 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; |
| 447 | 459 | } |
| 448 | 460 | |
| 449 | 461 | /// In-place implementation of RFC 3986, Section 5.2.4. |