Skip to content

Commit b6a4dd0

Browse files
authored
UrlEncode subject name (#1290)
1 parent d1bc5e3 commit b6a4dd0

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/Confluent.SchemaRegistry/Rest/RestService.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -279,32 +279,32 @@ public async Task<List<string>> GetSubjectsAsync()
279279
.ConfigureAwait(continueOnCapturedContext: false);
280280

281281
public async Task<List<int>> GetSubjectVersionsAsync(string subject)
282-
=> await RequestListOfAsync<int>($"subjects/{subject}/versions", HttpMethod.Get)
282+
=> await RequestListOfAsync<int>($"subjects/{WebUtility.UrlEncode(subject)}/versions", HttpMethod.Get)
283283
.ConfigureAwait(continueOnCapturedContext: false);
284284

285285
public async Task<RegisteredSchema> GetSchemaAsync(string subject, int version)
286-
=> SanitizeRegisteredSchema(await RequestAsync<RegisteredSchema>($"subjects/{subject}/versions/{version}", HttpMethod.Get)
286+
=> SanitizeRegisteredSchema(await RequestAsync<RegisteredSchema>($"subjects/{WebUtility.UrlEncode(subject)}/versions/{version}", HttpMethod.Get)
287287
.ConfigureAwait(continueOnCapturedContext: false));
288288

289289
public async Task<RegisteredSchema> GetLatestSchemaAsync(string subject)
290-
=> SanitizeRegisteredSchema(await RequestAsync<RegisteredSchema>($"subjects/{subject}/versions/latest", HttpMethod.Get)
290+
=> SanitizeRegisteredSchema(await RequestAsync<RegisteredSchema>($"subjects/{WebUtility.UrlEncode(subject)}/versions/latest", HttpMethod.Get)
291291
.ConfigureAwait(continueOnCapturedContext: false));
292292

293293
public async Task<int> RegisterSchemaAsync(string subject, Schema schema)
294294
=> schema.SchemaType == SchemaType.Avro
295295
// In the avro case, just send the schema string to maintain backards compatibility.
296-
? (await RequestAsync<SchemaId>($"subjects/{subject}/versions", HttpMethod.Post, new SchemaString(schema.SchemaString))
296+
? (await RequestAsync<SchemaId>($"subjects/{WebUtility.UrlEncode(subject)}/versions", HttpMethod.Post, new SchemaString(schema.SchemaString))
297297
.ConfigureAwait(continueOnCapturedContext: false)).Id
298-
: (await RequestAsync<SchemaId>($"subjects/{subject}/versions", HttpMethod.Post, schema)
298+
: (await RequestAsync<SchemaId>($"subjects/{WebUtility.UrlEncode(subject)}/versions", HttpMethod.Post, schema)
299299
.ConfigureAwait(continueOnCapturedContext: false)).Id;
300300

301301
// Checks whether a schema has been registered under a given subject.
302302
public async Task<RegisteredSchema> LookupSchemaAsync(string subject, Schema schema, bool ignoreDeletedSchemas)
303303
=> SanitizeRegisteredSchema(schema.SchemaType == SchemaType.Avro
304304
// In the avro case, just send the schema string to maintain backards compatibility.
305-
? await RequestAsync<RegisteredSchema>($"subjects/{subject}?deleted={!ignoreDeletedSchemas}", HttpMethod.Post, new SchemaString(schema.SchemaString))
305+
? await RequestAsync<RegisteredSchema>($"subjects/{WebUtility.UrlEncode(subject)}?deleted={!ignoreDeletedSchemas}", HttpMethod.Post, new SchemaString(schema.SchemaString))
306306
.ConfigureAwait(continueOnCapturedContext: false)
307-
: await RequestAsync<RegisteredSchema>($"subjects/{subject}?deleted={!ignoreDeletedSchemas}", HttpMethod.Post, schema)
307+
: await RequestAsync<RegisteredSchema>($"subjects/{WebUtility.UrlEncode(subject)}?deleted={!ignoreDeletedSchemas}", HttpMethod.Post, schema)
308308
.ConfigureAwait(continueOnCapturedContext: false));
309309

310310
#endregion Subjects
@@ -314,18 +314,18 @@ public async Task<RegisteredSchema> LookupSchemaAsync(string subject, Schema sch
314314
public async Task<bool> TestCompatibilityAsync(string subject, int versionId, Schema schema)
315315
=> schema.SchemaType == SchemaType.Avro
316316
// In the avro case, just send the schema string to maintain backards compatibility.
317-
? (await RequestAsync<CompatibilityCheck>($"compatibility/subjects/{subject}/versions/{versionId}", HttpMethod.Post, new SchemaString(schema.SchemaString))
317+
? (await RequestAsync<CompatibilityCheck>($"compatibility/subjects/{WebUtility.UrlEncode(subject)}/versions/{versionId}", HttpMethod.Post, new SchemaString(schema.SchemaString))
318318
.ConfigureAwait(continueOnCapturedContext: false)).IsCompatible
319-
: (await RequestAsync<CompatibilityCheck>($"compatibility/subjects/{subject}/versions/{versionId}", HttpMethod.Post, schema)
319+
: (await RequestAsync<CompatibilityCheck>($"compatibility/subjects/{WebUtility.UrlEncode(subject)}/versions/{versionId}", HttpMethod.Post, schema)
320320
.ConfigureAwait(continueOnCapturedContext: false)).IsCompatible;
321321

322322

323323
public async Task<bool> TestLatestCompatibilityAsync(string subject, Schema schema)
324324
=> schema.SchemaType == SchemaType.Avro
325325
// In the avro case, just send the schema string to maintain backards compatibility.
326-
? (await RequestAsync<CompatibilityCheck>($"compatibility/subjects/{subject}/versions/latest", HttpMethod.Post, new SchemaString(schema.SchemaString))
326+
? (await RequestAsync<CompatibilityCheck>($"compatibility/subjects/{WebUtility.UrlEncode(subject)}/versions/latest", HttpMethod.Post, new SchemaString(schema.SchemaString))
327327
.ConfigureAwait(continueOnCapturedContext: false)).IsCompatible
328-
: (await RequestAsync<CompatibilityCheck>($"compatibility/subjects/{subject}/versions/latest", HttpMethod.Post, schema)
328+
: (await RequestAsync<CompatibilityCheck>($"compatibility/subjects/{WebUtility.UrlEncode(subject)}/versions/latest", HttpMethod.Post, schema)
329329
.ConfigureAwait(continueOnCapturedContext: false)).IsCompatible;
330330

331331
#endregion Compatibility
@@ -337,15 +337,15 @@ public async Task<Compatibility> GetGlobalCompatibilityAsync()
337337
.ConfigureAwait(continueOnCapturedContext: false)).CompatibilityLevel;
338338

339339
public async Task<Compatibility> GetCompatibilityAsync(string subject)
340-
=> (await RequestAsync<Config>($"config/{subject}", HttpMethod.Get)
340+
=> (await RequestAsync<Config>($"config/{WebUtility.UrlEncode(subject)}", HttpMethod.Get)
341341
.ConfigureAwait(continueOnCapturedContext: false)).CompatibilityLevel;
342342

343343
public async Task<Config> SetGlobalCompatibilityAsync(Compatibility compatibility)
344344
=> await RequestAsync<Config>("config", HttpMethod.Put, new Config(compatibility))
345345
.ConfigureAwait(continueOnCapturedContext: false);
346346

347347
public async Task<Config> SetCompatibilityAsync(string subject, Compatibility compatibility)
348-
=> await RequestAsync<Config>($"config/{subject}", HttpMethod.Put, new Config(compatibility))
348+
=> await RequestAsync<Config>($"config/{WebUtility.UrlEncode(subject)}", HttpMethod.Put, new Config(compatibility))
349349
.ConfigureAwait(continueOnCapturedContext: false);
350350

351351
#endregion Config

0 commit comments

Comments
 (0)