Skip to content

Commit f84ce7d

Browse files
#172 - Escape document IDs
1 parent fc107c7 commit f84ce7d

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/CouchDB.Driver/CouchDatabase.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ internal CouchDatabase(IFlurlClient flurlClient, CouchOptions options, QueryCont
8181
public async Task<TSource?> FindAsync(string docId, FindOptions options, CancellationToken cancellationToken = default)
8282
{
8383
IFlurlRequest request = NewRequest()
84-
.AppendPathSegment(docId);
84+
.AppendPathSegment(Uri.EscapeDataString(docId));
8585

8686
if (options.Conflicts)
8787
request = request.SetQueryParam("conflicts", "true");
@@ -240,7 +240,7 @@ public async Task<TSource> AddOrUpdateAsync(TSource document, AddOrUpdateOptions
240240
}
241241

242242
IFlurlRequest request = NewRequest()
243-
.AppendPathSegment(document.Id);
243+
.AppendPathSegment(Uri.EscapeDataString(document.Id));
244244

245245
if (options.Batch)
246246
request = request.SetQueryParam("batch", "ok");
@@ -268,7 +268,7 @@ public async Task RemoveAsync(TSource document, bool batch = false, Cancellation
268268
Check.NotNull(document, nameof(document));
269269

270270
IFlurlRequest request = NewRequest()
271-
.AppendPathSegment(document.Id);
271+
.AppendPathSegment(Uri.EscapeDataString(document.Id));
272272

273273
if (batch)
274274
{
@@ -377,7 +377,7 @@ private async Task UpdateAttachments(TSource document, CancellationToken cancell
377377
new FileStream(attachment.FileInfo.FullName, FileMode.Open));
378378

379379
AttachmentResult response = await NewRequest()
380-
.AppendPathSegment(document.Id)
380+
.AppendPathSegment(Uri.EscapeDataString(document.Id))
381381
.AppendPathSegment(Uri.EscapeUriString(attachment.Name))
382382
.WithHeader("Content-Type", attachment.ContentType)
383383
.WithHeader("If-Match", document.Rev)
@@ -395,8 +395,8 @@ private async Task UpdateAttachments(TSource document, CancellationToken cancell
395395
foreach (CouchAttachment attachment in document.Attachments.GetDeletedAttachments())
396396
{
397397
AttachmentResult response = await NewRequest()
398-
.AppendPathSegment(document.Id)
399-
.AppendPathSegment(attachment.Name)
398+
.AppendPathSegment(Uri.EscapeDataString(document.Id))
399+
.AppendPathSegment(Uri.EscapeDataString(attachment.Name))
400400
.WithHeader("If-Match", document.Rev)
401401
.DeleteAsync(cancellationToken)
402402
.ReceiveJson<AttachmentResult>()
@@ -664,7 +664,7 @@ public async Task<Stream> DownloadAttachmentAsStreamAsync(CouchAttachment attach
664664
}
665665

666666
return await NewRequest()
667-
.AppendPathSegment(attachment.DocumentId)
667+
.AppendPathSegment(Uri.EscapeDataString(attachment.DocumentId))
668668
.AppendPathSegment(Uri.EscapeUriString(attachment.Name))
669669
.WithHeader("If-Match", attachment.DocumentRev)
670670
.GetStreamAsync(cancellationToken)

src/CouchDB.Driver/Local/LocalDocuments.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public Task<TSource> GetAsync<TSource>(string id, CancellationToken cancellation
6767
{
6868
Check.NotNull(id, nameof(id));
6969
return NewRequest()
70-
.AppendPathSegments(GetLocalId(id))
70+
.AppendPathSegments(GetLocalId(Uri.EscapeDataString(id)))
7171
.GetJsonAsync<TSource>(cancellationToken)
7272
.SendRequestAsync();
7373
}
@@ -78,7 +78,7 @@ public Task CreateOrUpdateAsync<TSource>(TSource document, CancellationToken can
7878
{
7979
Check.NotNull(document, nameof(document));
8080
return NewRequest()
81-
.AppendPathSegments(GetLocalId(document.Id))
81+
.AppendPathSegments(GetLocalId(Uri.EscapeDataString(document.Id)))
8282
.PutJsonAsync(document, cancellationToken)
8383
.SendRequestAsync();
8484
}
@@ -89,7 +89,7 @@ public Task DeleteAsync<TSource>(TSource document, CancellationToken cancellatio
8989
{
9090
Check.NotNull(document, nameof(document));
9191
return NewRequest()
92-
.AppendPathSegments(GetLocalId(document.Id))
92+
.AppendPathSegments(GetLocalId(Uri.EscapeDataString(document.Id)))
9393
.DeleteAsync(cancellationToken)
9494
.SendRequestAsync();
9595
}

0 commit comments

Comments
 (0)