diff options
author | bptato <nincsnevem662@gmail.com> | 2024-03-11 22:03:16 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-03-11 22:05:34 +0100 |
commit | 75865752dd0e0db44916fa493b78e3761279359c (patch) | |
tree | 2582921b4fd2094d1c60d9286a8ac95d75d98e4f /src | |
parent | 5e2d67cdd5ad4220426b19592ddf2f827af75f0b (diff) | |
download | chawan-75865752dd0e0db44916fa493b78e3761279359c.tar.gz |
mailcap: better error messages, accept \ as newline escape
the backslash thing is in the RFC, I just forgot to add it
Diffstat (limited to 'src')
-rw-r--r-- | src/config/mailcap.nim | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/config/mailcap.nim b/src/config/mailcap.nim index 725c2c22..90815249 100644 --- a/src/config/mailcap.nim +++ b/src/config/mailcap.nim @@ -15,6 +15,7 @@ type stream: Stream hasbuf: bool buf: char + line: int MailcapFlags* = enum NEEDSTERMINAL = "needsterminal" @@ -40,7 +41,15 @@ proc consume(state: var MailcapParser): char = if state.hasbuf: state.hasbuf = false return state.buf - return state.stream.readChar() + var c = state.stream.readChar() + if c == '\\' and not state.stream.atEnd: + let c2 = state.stream.readChar() + if c2 == '\n' and not state.stream.atEnd: + inc state.line + c = state.stream.readChar() + if c == '\n': + inc state.line + return c proc reconsume(state: var MailcapParser, c: char) = state.buf = c @@ -72,7 +81,8 @@ proc consumeTypeField(state: var MailcapParser): Result[string, string] = s &= c break if c notin AsciiAlphaNumeric + {'-', '*'}: - return err("Invalid character encountered in type field") + return err("line " & $state.line & ": invalid character in type field: " & + c) s &= c.toLowerAscii() if not state.has(): return err("Missing subtype") @@ -83,7 +93,8 @@ proc consumeTypeField(state: var MailcapParser): Result[string, string] = state.reconsume(c) break if c notin AsciiAlphaNumeric + {'-', '.', '*', '_', '+'}: - return err("Invalid character encountered in subtype field") + return err("line " & $state.line & + ": invalid character in subtype field: " & c) s &= c.toLowerAscii() var c: char if not state.skipBlanks(c) or c != ';': @@ -106,7 +117,8 @@ proc consumeCommand(state: var MailcapParser): Result[string, string] = quoted = true continue if c notin Ascii - Controls: - return err("Invalid character encountered in command") + return err("line " & $state.line & ": invalid character in command: " & + c) else: quoted = false s &= c @@ -163,11 +175,11 @@ proc consumeField(state: var MailcapParser, entry: var MailcapEntry): return ok(state.consume() == ';') else: if c in Controls: - return err("Invalid character encountered in field") + return err("line " & $state.line & ": invalid character in field: " & c) buf &= c proc parseMailcap*(stream: Stream): Result[Mailcap, string] = - var state = MailcapParser(stream: stream) + var state = MailcapParser(stream: stream, line: 1) var mailcap: Mailcap while not stream.atEnd(): let c = state.consume() |