diff options
author | bptato <nincsnevem662@gmail.com> | 2024-04-18 20:53:36 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-04-18 21:12:50 +0200 |
commit | c23ea622d1b34d3d290670e60e231f4f236fec50 (patch) | |
tree | 739abbf0490c28f5446469d7244a20a9a0a03502 /src/loader | |
parent | 38db6ab5be80b255fe40df715adc3b5852875cdd (diff) | |
download | chawan-c23ea622d1b34d3d290670e60e231f4f236fec50.tar.gz |
url, twtstr: correct number parsing
* do not use std's parse*Int; they accept weird stuff that we do not want to accept in any case * fix bug in parseHost where a parseIpv4 failure would result in an empty host * do not use isDigit, isAlphaAscii * improve parse*IntImpl error handling
Diffstat (limited to 'src/loader')
-rw-r--r-- | src/loader/loader.nim | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/loader/loader.nim b/src/loader/loader.nim index 6a8e9164..21511c56 100644 --- a/src/loader/loader.nim +++ b/src/loader/loader.nim @@ -362,14 +362,11 @@ func find(cacheMap: seq[CachedItem]; id: int): int = proc loadFromCache(ctx: LoaderContext; client: ClientData; handle: LoaderHandle; request: Request) = - var id = -1 - var startFrom = 0 - try: - id = parseInt(request.url.pathname) - if request.url.query.isSome: - startFrom = parseInt(request.url.query.get) - except ValueError: - discard + let id = parseInt32(request.url.pathname).get(-1) + let startFrom = if request.url.query.isSome: + parseInt32(request.url.query.get).get(0) + else: + 0 let n = client.cacheMap.find(id) if n != -1: let ps = newPosixStream(client.cacheMap[n].path, O_RDONLY, 0) |