From 6e6d9e2ab875ffdb9dcaf1a2ed689a1390f72848 Mon Sep 17 00:00:00 2001 From: bptato Date: Tue, 1 Oct 2024 21:40:26 +0200 Subject: twtstr: misc refactorings --- src/js/base64.nim | 2 +- src/loader/loader.nim | 2 +- src/utils/twtstr.nim | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/js/base64.nim b/src/js/base64.nim index c44fb5f6..f9137fb3 100644 --- a/src/js/base64.nim +++ b/src/js/base64.nim @@ -12,7 +12,7 @@ proc atob*(data: string): DOMResult[NarrowString] = # Note: the actual atob implementation (atob0) is in twtstr. let r = atob0(data) if r.isNone: - return errDOMException(r.error, "InvalidCharacterError") + return errDOMException($r.error, "InvalidCharacterError") return ok(NarrowString(r.get)) const AMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" diff --git a/src/loader/loader.nim b/src/loader/loader.nim index 0d6c655a..74a2a65f 100644 --- a/src/loader/loader.nim +++ b/src/loader/loader.nim @@ -806,7 +806,7 @@ proc loadData(ctx: LoaderContext; handle: InputHandle; request: Request) = handle.close() return let sd = ct.len + 1 # data start - let body = percentDecode(url.path.s, sd) + let body = percentDecode(url.path.s.toOpenArray(sd, url.path.s.high)) if ct.endsWith(";base64"): let d = atob0(body) # decode from ct end + 1 if d.isNone: diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index 46787553..a83dfeef 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -353,8 +353,8 @@ func percentEncode*(s: openArray[char]; set: set[char]; spaceAsPlus = false): result = "" result.percentEncode(s, set, spaceAsPlus) -func percentDecode*(input: openArray[char]; si = 0): string = - var i = si +func percentDecode*(input: openArray[char]): string = + var i = 0 while i < input.len: let c = input[i] if c != '%' or i + 2 >= input.len: @@ -627,7 +627,7 @@ func atob(c: char): uint8 {.inline.} = return 63 return uint8.high -func atob0*(data: string): Result[string, string] = +func atob0*(data: string): Result[string, cstring] = var outs = newStringOfCap(data.len div 4 * 3) var buf: array[4, uint8] var i = 0 -- cgit 1.4.1-2-gfad0