bundle-uri: stop sending invalid bundle configuration

When bundle-URI info is requested by the client, the server responds with all "bundle.*" config lines as key=value packet lines. On the client-side, the received bundle config packet lines are always expected to contain both a key and a value otherwise the client errors out during parsing. The server performs no validation of the read bundle configuration though which results in any misconfiguration on the server-side, such as bundle configuration with an empty value, being blindly sent to the client. To avoid having the server transmit invalid configuration to clients, only send bundle configuration that has non-empty values. This change makes bundle-URI information sent by the server syntactically correct, but semantically it still can be invalid. For example the server may end up sending `bundle.bundle-1.creationToken`, but be lacking a `bundle.bundle-1.uri` for that bundle. The `uri` is mandatory, thus the client cannot process this bundle and will error with the message: error: bundle 'bundle-1' has no uri Fixing this would require a more complex solution, because bundles need to be validated as a whole and not line-by-line. This is considered outside the scope of this change. Co-authored-by: Toon Claes <toon@iotcl.com> Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Toon Claes <toon@iotcl.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Justin Tobler committed Jul 8, 2026 at 17:03 UTC 50de1169e4bf5cff947e10f64e9855669fdd2849
2 files changed +29 -2
bundle-uri.c
+6 -2
@@ -946,8 +946,12 @@ static int config_to_packet_line(const char *key, const char *value,
946 {
947 struct packet_reader *writer = data;
948
949 - if (starts_with(key, "bundle."))
950 - packet_write_fmt(writer->fd, "%s=%s", key, value);
949 + if (starts_with(key, "bundle.")) {
950 + if (value && *value)
951 + packet_write_fmt(writer->fd, "%s=%s", key, value);
952 + else
953 + warning(_("config '%s' has no value"), key);
954 + }
955
956 return 0;
957 }
t/lib-bundle-uri-protocol.sh
+23
@@ -214,3 +214,26 @@ test_expect_success "test bundle-uri with $BUNDLE_URI_PROTOCOL:// using protocol
214 >actual &&
215 test_cmp_config_output expect actual
216 '
217 +
218 +test_expect_success "test bundle-uri with $BUNDLE_URI_PROTOCOL:// using protocol v2 with empty value" '
219 + test_config -C "$BUNDLE_URI_PARENT" \
220 + bundle.bundle1.uri "$BUNDLE_URI_BUNDLE_URI_ESCAPED-1.bdl" &&
221 + test_config -C "$BUNDLE_URI_PARENT" \
222 + bundle.bundle2.uri "" &&
223 +
224 + # The empty bundle.bundle2.uri value is invalid configuration and the
225 + # server must not advertise it to the client.
226 + cat >expect <<-EOF &&
227 + [bundle]
228 + version = 1
229 + mode = all
230 + [bundle "bundle1"]
231 + uri = $BUNDLE_URI_BUNDLE_URI_ESCAPED-1.bdl
232 + EOF
233 +
234 + test-tool bundle-uri \
235 + ls-remote \
236 + "$BUNDLE_URI_REPO_URI" \
237 + >actual &&
238 + test_cmp_config_output expect actual
239 +'