Skip to content

Commit 0f23bba

Browse files
committed
Fix GenericOS.getenv returning a raw str, return an Option.t[str] instead.
1 parent e2f7f11 commit 0f23bba

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/comp/front/extenv.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,18 @@ fn expand_syntax_ext(parser.parser p,
2323
p.err("malformed #env call");
2424
}
2525

26+
// FIXME: if this was more thorough it would manufacture an
27+
// Option.t[str] rather than just an maybe-empty string.
28+
2629
auto var = expr_to_str(p, args.(0));
27-
auto val = GenericOS.getenv(var);
28-
ret make_new_str(sp, val);
30+
alt (GenericOS.getenv(var)) {
31+
case (Option.none[str]) {
32+
ret make_new_str(sp, "");
33+
}
34+
case (Option.some[str](?s)) {
35+
ret make_new_str(sp, s);
36+
}
37+
}
2938
}
3039

3140
// FIXME: duplicate code copied from extfmt.

src/lib/GenericOS.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
fn getenv(str n) -> str {
2-
ret Str.str_from_cstr(OS.libc.getenv(Str.buf(n)));
1+
fn getenv(str n) -> Option.t[str] {
2+
auto s = OS.libc.getenv(Str.buf(n));
3+
if (s == 0 as Str.sbuf) {
4+
ret Option.none[str];
5+
} else {
6+
ret Option.some[str](Str.str_from_cstr(s));
7+
}
38
}
49

src/lib/Term.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn reset(IO.buf_writer writer) {
3131
}
3232

3333
fn color_supported() -> bool {
34-
ret Str.eq(GenericOS.getenv("TERM"), "xterm-color");
34+
ret GenericOS.getenv("TERM") == Option.some[str]("xterm-color");
3535
}
3636

3737
fn set_color(IO.buf_writer writer, u8 first_char, u8 color) {

0 commit comments

Comments
 (0)