diff options
author | bptato <nincsnevem662@gmail.com> | 2022-01-25 16:40:55 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-01-25 16:40:55 +0100 |
commit | 8fb2b9a0a505a9051bac04ab0163b20db95b86fb (patch) | |
tree | d291a0da551a2682d3b6fef06daa81b173521702 | |
parent | 16fa06be2a19780759195251c4a1f242ee0f8d10 (diff) | |
download | chawan-8fb2b9a0a505a9051bac04ab0163b20db95b86fb.tar.gz |
Fix some path bugs and misc. warnings
-rw-r--r-- | src/client.nim | 8 | ||||
-rw-r--r-- | src/io/lineedit.nim | 8 | ||||
-rw-r--r-- | src/io/loader.nim | 5 | ||||
-rw-r--r-- | src/types/url.nim | 17 | ||||
-rw-r--r-- | src/utils/twtstr.nim | 5 |
5 files changed, 30 insertions, 13 deletions
diff --git a/src/client.nim b/src/client.nim index 2cce60a7..330b04aa 100644 --- a/src/client.nim +++ b/src/client.nim @@ -63,12 +63,14 @@ proc nextBuffer(client: Client) = proc discardBuffer(client: Client) = if client.buffer.next != nil: - client.buffer.sourcepair.sourcepair = nil + if client.buffer.sourcepair != nil: + client.buffer.sourcepair.sourcepair = nil client.buffer.next.prev = client.buffer.prev client.buffer = client.buffer.next client.buffer.redraw = true elif client.buffer.prev != nil: - client.buffer.sourcepair.sourcepair = nil + if client.buffer.sourcepair != nil: + client.buffer.sourcepair.sourcepair = nil client.buffer.prev.next = client.buffer.next client.buffer = client.buffer.prev client.buffer.redraw = true @@ -139,7 +141,7 @@ proc loadUrl(client: Client, url: string, ctype = "") = client.gotoUrl(url, none(Url), true, true, ctype) else: try: - let cdir = parseUrl("file://" & getCurrentDir() & '/') + let cdir = parseUrl("file://" & getCurrentDir() & DirSep) client.gotoUrl(url, cdir, true, true, ctype) except LoadError: client.gotoUrl("http://" & url, none(Url), true, true, ctype) diff --git a/src/io/lineedit.nim b/src/io/lineedit.nim index b453bef5..67b6194b 100644 --- a/src/io/lineedit.nim +++ b/src/io/lineedit.nim @@ -152,7 +152,7 @@ proc readLine*(current: var string, minlen, maxlen: int): bool = of ACTION_LINED_BACKSPACE: if state.cursor > 0: let w = state.news[state.cursor - 1].lwidth() - state.news.delete(state.cursor - 1, state.cursor - 1) + state.news.delete(state.cursor - 1..state.cursor - 1) dec state.cursor if state.cursor == state.news.len and state.shift == 0: state.backward(w) @@ -162,7 +162,7 @@ proc readLine*(current: var string, minlen, maxlen: int): bool = of ACTION_LINED_DELETE: if state.cursor > 0 and state.cursor < state.news.len: let w = state.news[state.cursor - 1].lwidth() - state.news.delete(state.cursor, state.cursor) + state.news.delete(state.cursor..state.cursor) if state.cursor == state.news.len and state.shift == 0: state.kill(w) else: @@ -171,7 +171,7 @@ proc readLine*(current: var string, minlen, maxlen: int): bool = state.escNext = true of ACTION_LINED_CLEAR: if state.cursor > 0: - state.news.delete(0, state.cursor - 1) + state.news.delete(0..state.cursor - 1) state.cursor = 0 state.zeroShiftRedraw() of ACTION_LINED_KILL: @@ -232,7 +232,7 @@ proc readLine*(current: var string, minlen, maxlen: int): bool = break if chars > 0: let w = state.news.lwidth(state.cursor - chars, state.cursor) - state.news.delete(state.cursor - chars, state.cursor - 1) + state.news.delete(state.cursor - chars..state.cursor - 1) state.cursor -= chars if state.cursor == state.news.len and state.shift == 0: state.backward(w) diff --git a/src/io/loader.nim b/src/io/loader.nim index 3ef5320e..5bd35a90 100644 --- a/src/io/loader.nim +++ b/src/io/loader.nim @@ -20,7 +20,10 @@ proc newFileLoader*(): FileLoader = proc getPage*(loader: FileLoader, url: Url): LoadResult = if url.scheme == "file": - let path = url.path.serialize_unicode() + when defined(windows) or defined(OS2) or defined(DOS): + let path = url.path.serialize_unicode_windows() + else: + let path = url.path.serialize_unicode() result.contenttype = guessContentType(path) result.s = newFileStream(path, fmRead) elif url.scheme == "http" or url.scheme == "https": diff --git a/src/types/url.nim b/src/types/url.nim index 00a5fd51..c8c7085e 100644 --- a/src/types/url.nim +++ b/src/types/url.nim @@ -323,6 +323,7 @@ proc append(path: var UrlPath, s: string) = path.ss.add(s) template includes_credentials(url: Url): bool = url.username != "" or url.password != "" +template is_windows_drive_letter(s: string): bool = s.len == 2 and s[0] in Letters and (s[1] == ':' or s[1] == '|') #TODO encoding proc basicParseUrl*(input: string, base = none(Url), url: var Url = Url(), override: bool = false): Option[Url] = @@ -606,7 +607,7 @@ proc basicParseUrl*(input: string, base = none(Url), url: var Url = Url(), overr state = PATH_STATE dec pointer of FILE_HOST_STATE: - if (not has or c in {'/', '?', '#'}): + if (not has or c in {'/', '\\', '?', '#'}): dec pointer if not override and buffer.is_windows_drive_letter: #TODO validation error @@ -801,6 +802,20 @@ func serialize_unicode*(path: UrlPath): string {.inline.} = result &= '/' result &= percentDecode(s) +func serialize_unicode_dos*(path: UrlPath): string {.inline.} = + if path.opaque: + return percentDecode(path.s) + var i = 0 + if i < path.ss.len: + if path.ss[i].is_windows_drive_letter: + result &= path.ss[i] + inc i + while i < path.ss.len: + let s = path.ss[i] + result &= '\\' + result &= percentDecode(s) + inc i + func serialize*(url: Url, excludefragment = false): string = result = url.scheme & ':' if url.host.issome: diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index e2d06535..a0dd1b3f 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -128,9 +128,6 @@ func toAsciiLower*(str: string): string = for i in 0..str.high: result[i] = str[i].tolower() -func getrune(s: string): Rune = - return s.toRunes()[0] - func genHexCharMap(): seq[int] = for i in 0..255: case chr(i) @@ -565,7 +562,7 @@ proc expandPath*(path: string): string = while path[i] != '/': usr &= path[i] inc i - let p = getpwnam(usr) + let p = getpwnam(cstring(usr)) if p != nil: result = $p.pw_dir / path.substr(i) |