question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

object.eval with additional newline

See original GitHub issue

Hi

I am using Scriban with a custom object that contains basically labels.

Lets say I have the object Labels = { Label1: “L1”, Label2: “L2”}

I can use {{ Labels.Label1 }} and are getting the correct value “L1”

As we want some custom labels which are not known at runtime, we have a local object custom: [ {key: “Labels.Label1”, value: “C1”} ]

Now I have a function that looks into the custom array and tries to find an entry, and if nothing is found, it evaluates the given “item” using object.eval.

When I call

“Labels.Label1” | label “:”

I get “L1:” back, note that the colon is directly behind “L1”

When I call

“Labels.Label2” | label “:” I get “L21:” back, note that the colon is in a new line behind “L2”

Why is this happenng?

{{func byKey(label)
   ret label.key == key 
end}}

{{func label(item, suffix = "")

    key = item
    labelObject = custom | array.filter @byKey
    if labelObject.size == 1 
        ret (labelObject[0].label) + suffix
    else
        ret (item | asString) + suffix
    end
end
}}

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
klauswieselcommented, Jun 17, 2022

We will try to put something together on your basis. Thanks so far

0reactions
xoofxcommented, Jun 17, 2022

Thanks for the explanation, but what I see is an output, but I don’t see why it is failing. Eval is working fine in the case as I showed above, so a reproducible small program is necessary because I’m missing something here. You are mentioning a newline problem with eval, I don’t see this correctly explained.

Note, this editor allows to enter html text 😉

<div>C1:</div>
L2<div>:</div>
Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I write an `eval` command containing a new line ...
Since you're using bash : eval $'alias df5=df\ndf5 -h'. The $'...' is a "C string", and bash would expand the \n within it...
Read more >
javascript - is there a way to use newlines in xdmp.eval()
I tried using a '+' sign to generate a strng over more then one line, swapping single and double quotes but no luck....
Read more >
Solved: Add Line Breaks with Eval
Solved: This might be a silly question, but has anyone figured out how to add line breaks to text that has been evaluated...
Read more >
Python eval(): Evaluate Expressions Dynamically
This function can be handy when you're trying to dynamically evaluate Python expressions from any input that comes as a string or a...
Read more >
[Solved] Issue searching for newline character with StrFind
It works fine, except sometimes, with the return (line break) ... I just run a new test, replacing the star by another character,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found