Skip to content

Commit 633166e

Browse files
committed
config: trim whitespace from ints and bools in the database
Previously using a text editor might result in a string like `1\n` which would be rejected. This patch trims the unnecessary whitespace from the beginning and end of ints and bools so this string will be parsed as `1`. Signed-off-by: David Scott <[email protected]>
1 parent 796a682 commit 633166e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/ofs/active_config.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,18 @@ module Make(Time: Mirage_time_lwt.S)(FLOW: Mirage_flow_lwt.S) = struct
228228
| Some x -> Lwt.return x
229229
) vs
230230

231+
open Astring
232+
231233
let int t ~default path =
232234
string t ~default:(string_of_int default) path
233235
>>= fun strings ->
234-
let parse s = Lwt.return (try int_of_string s with _ -> default) in
236+
let parse s = Lwt.return (try int_of_string @@ String.trim ~drop:Char.Ascii.is_white s with _ -> default) in
235237
changes @@ map parse strings
236238

237239
let bool t ~default path =
238240
string t ~default:(string_of_bool default) path
239241
>>= fun strings ->
240-
let parse s = Lwt.return (try bool_of_string s with _ -> default) in
242+
let parse s = Lwt.return (try bool_of_string @@ String.trim ~drop:Char.Ascii.is_white s with _ -> default) in
241243
changes @@ map parse strings
242244

243245
end

0 commit comments

Comments
 (0)