Fix modulo operation and custom Uri struct init

pull/7029/head
Kristófer R 2025-04-30 23:54:42 -04:00
parent 0e74b8027a
commit 19ca1bfb1c
No known key found for this signature in database
1 changed files with 8 additions and 7 deletions

View File

@ -1082,17 +1082,18 @@ pub const StreamHandler = struct {
// address are non-digits, e.g. 'ff', and thus an invalid port. // address are non-digits, e.g. 'ff', and thus an invalid port.
// //
// Example: file://12:34:56:78:90:12/path/to/file // Example: file://12:34:56:78:90:12/path/to/file
if (e != error.InvalidPort) return;
// Insufficient length to have a mac address in the hostname. // Insufficient length to have a mac address in the hostname.
if (url.len < 24) { if (url.len < 24) {
log.warn("invalid url in OSC 7: {}", .{e}); log.warn("invalid MAC address in OSC 7: insufficient length", .{});
return; return;
} }
// The first '/' after the scheme marks the end of the hostname. If the hostname is // The first '/' after the scheme marks the end of the hostname. If the hostname is
// not 17 characters, it's not a mac address. // not 17 characters, it's not a mac address.
if (std.mem.indexOfScalarPos(u8, url, 7, '/') != 24) { if (std.mem.indexOfScalarPos(u8, url, 7, '/') != 24) {
log.warn("invalid url in OSC 7: {}", .{e}); log.warn("invalid MAC address in OSC 7: invalid scheme", .{});
return; return;
} }
@ -1102,14 +1103,14 @@ pub const StreamHandler = struct {
for (0..mac_address.len) |i| { for (0..mac_address.len) |i| {
const c = mac_address[i]; const c = mac_address[i];
if (i + 1 % 3 == 0) { if ((i + 1) % 3 == 0) {
if (c != ':') { if (c != ':') {
log.warn("invalid url in OSC 7: {}", .{e}); log.warn("invalid MAC address in OSC 7: missing colon", .{});
return; return;
} }
} else { } else {
if (!std.mem.containsAtLeastScalar(u8, "0123456789abcdef", 1, mac_address[i])) { if (!std.mem.containsAtLeastScalar(u8, "0123456789ABCDEFabcdef", 1, mac_address[i])) {
log.warn("invalid url in OSC 7: {}", .{e}); log.warn("invalid MAC address in OSC 7: invalid character '{c}' at position '{d}'", .{ mac_address[i], i });
return; return;
} }
} }
@ -1125,7 +1126,7 @@ pub const StreamHandler = struct {
// Same compliance factor as std.Uri.parse(), i.e. not at all compliant with the URI // Same compliance factor as std.Uri.parse(), i.e. not at all compliant with the URI
// spec. // spec.
break :uri .{ break :uri .{
.scheme = "file://", .scheme = "file",
.host = .{ .percent_encoded = mac_address }, .host = .{ .percent_encoded = mac_address },
.path = .{ .percent_encoded = url[24..uri_path_end_idx] }, .path = .{ .percent_encoded = url[24..uri_path_end_idx] },
}; };