Skip to content

Commit 2ae113d

Browse files
authored
fixed jrpc config treating empty strings as non null (#727)
1 parent 7a7576c commit 2ae113d

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/Server.zig

+17-2
Original file line numberDiff line numberDiff line change
@@ -2120,8 +2120,15 @@ fn didChangeConfigurationHandler(server: *Server, writer: anytype, id: types.Req
21202120
if (req.settings) |configuration| {
21212121
inline for (std.meta.fields(Config.Configuration)) |field| {
21222122
if (@field(configuration, field.name)) |value| {
2123-
@field(server.config, field.name) = if (@TypeOf(value) == []const u8) try server.allocator.dupe(u8, value) else value;
2124-
log.debug("setting configuration option '{s}' to '{any}'", .{ field.name, value });
2123+
blk: {
2124+
if (@TypeOf(value) == []const u8) {
2125+
if (value.len == 0) {
2126+
break :blk;
2127+
}
2128+
}
2129+
@field(server.config, field.name) = if (@TypeOf(value) == []const u8) try server.allocator.dupe(u8, value) else value;
2130+
log.debug("setting configuration option '{s}' to '{any}'", .{ field.name, value });
2131+
}
21252132
}
21262133
}
21272134

@@ -2653,6 +2660,14 @@ pub fn processJsonRpc(server: *Server, writer: anytype, json: []const u8) !void
26532660
const new_value: field.field_type = switch (ft) {
26542661
[]const u8 => switch (value) {
26552662
.String => |s| blk: {
2663+
if (s.len == 0) {
2664+
if (field.field_type == ?[]const u8) {
2665+
break :blk null;
2666+
}
2667+
else {
2668+
break :blk s;
2669+
}
2670+
}
26562671
var nv = try server.allocator.dupe(u8, s);
26572672
if (@field(server.config, field.name)) |prev_val| server.allocator.free(prev_val);
26582673
break :blk nv;

0 commit comments

Comments
 (0)