Skip to content

Commit 97c92d7

Browse files
committed
replace trimmed_path with path
1 parent aa88480 commit 97c92d7

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/url.zig

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,31 +81,31 @@ pub const URL = struct {
8181
/// For URLs without a path, it will add src as the path.
8282
pub fn stitch(
8383
allocator: Allocator,
84-
path: []const u8,
84+
raw_path: []const u8,
8585
base: []const u8,
8686
comptime opts: StitchOpts,
8787
) !StitchReturn(opts) {
88-
const trimmed_path = std.mem.trim(u8, path, &.{ '\n', '\r' });
88+
const path = std.mem.trim(u8, raw_path, &.{ '\n', '\r' });
8989

90-
if (base.len == 0 or isCompleteHTTPUrl(trimmed_path)) {
91-
return simpleStitch(allocator, trimmed_path, opts);
90+
if (base.len == 0 or isCompleteHTTPUrl(path)) {
91+
return simpleStitch(allocator, path, opts);
9292
}
9393

94-
if (trimmed_path.len == 0) {
94+
if (path.len == 0) {
9595
return simpleStitch(allocator, base, opts);
9696
}
9797

98-
if (std.mem.startsWith(u8, trimmed_path, "//")) {
98+
if (std.mem.startsWith(u8, path, "//")) {
9999
// network-path reference
100100
const index = std.mem.indexOfScalar(u8, base, ':') orelse {
101-
return simpleStitch(allocator, trimmed_path, opts);
101+
return simpleStitch(allocator, path, opts);
102102
};
103103

104104
const protocol = base[0..index];
105105
if (comptime opts.null_terminated) {
106-
return std.fmt.allocPrintSentinel(allocator, "{s}:{s}", .{ protocol, trimmed_path }, 0);
106+
return std.fmt.allocPrintSentinel(allocator, "{s}:{s}", .{ protocol, path }, 0);
107107
}
108-
return std.fmt.allocPrint(allocator, "{s}:{s}", .{ protocol, trimmed_path });
108+
return std.fmt.allocPrint(allocator, "{s}:{s}", .{ protocol, path });
109109
}
110110

111111
// Quick hack because domains have to be at least 3 characters.
@@ -119,11 +119,11 @@ pub const URL = struct {
119119
root = base[0 .. pos + protocol_end];
120120
}
121121

122-
if (trimmed_path[0] == '/') {
122+
if (path[0] == '/') {
123123
if (comptime opts.null_terminated) {
124-
return std.fmt.allocPrintSentinel(allocator, "{s}{s}", .{ root, trimmed_path }, 0);
124+
return std.fmt.allocPrintSentinel(allocator, "{s}{s}", .{ root, path }, 0);
125125
}
126-
return std.fmt.allocPrint(allocator, "{s}{s}", .{ root, trimmed_path });
126+
return std.fmt.allocPrint(allocator, "{s}{s}", .{ root, path });
127127
}
128128

129129
var old_path = std.mem.trimStart(u8, base[root.len..], "/");
@@ -135,7 +135,7 @@ pub const URL = struct {
135135

136136
// We preallocate all of the space possibly needed.
137137
// This is the root, old_path, new path, 3 slashes and perhaps a null terminated slot.
138-
var out = try allocator.alloc(u8, root.len + old_path.len + trimmed_path.len + 3 + if (comptime opts.null_terminated) 1 else 0);
138+
var out = try allocator.alloc(u8, root.len + old_path.len + path.len + 3 + if (comptime opts.null_terminated) 1 else 0);
139139
var end: usize = 0;
140140
@memmove(out[0..root.len], root);
141141
end += root.len;
@@ -148,8 +148,8 @@ pub const URL = struct {
148148
out[end] = '/';
149149
end += 1;
150150
}
151-
@memmove(out[end .. end + trimmed_path.len], trimmed_path);
152-
end += trimmed_path.len;
151+
@memmove(out[end .. end + path.len], path);
152+
end += path.len;
153153

154154
var read: usize = root.len;
155155
var write: usize = root.len;

0 commit comments

Comments
 (0)