Hey for some reason using: ``` val filesystem: Env...
# http4k
r
Hey for some reason using:
Copy code
val filesystem: Environment = Environment.from(File("test.yml"))
var testString
var testStringLens: BiDiLens<Environment, String?> = EnvironmentKey.string().optional("TESTKEY")
testString = environment[testStringLens]
Only returns the string up to the first comma. Example: (yml) TESTKEY: “test1 , test2” Example: (properties) TESTKEY= “test1, test2" Will only return test1 as the string. How do I solve this? do I need to escape the string somehow? I’m trying to actually read a json from a file under a key.
I used multi and joined them as string but I wonder if that is okay to do like that, I mean I got the result, but is the method okay..
s
I think you're right that this does not behave as expected:
Copy code
val lens = EnvironmentKey.optional("SOME_VALUE")
        assertThat(lens(Environment.from("SOME_VALUE" to "80,81")), equalTo("80,81"))
This assertion currently fails with actual being
80
rather than
80,81
So I say for now use the multi and we'll look into why we're getting such behaviour
👍 1
r
Thanks for the help
s
You're welcome 🙂 Sorry for the trouble
r
No trouble, thanks for the library
d
Not obvious, but expected. The default separator is a comma in environments. You can override it when you create the environment and it should work as you need.
This is totally to do with the way that lenses are constructed. A singular lens will extract the first only value from the "list". Eg with headers it will just grab the first instance of the header that it finds even though there may be multiple