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.

Extend @R_str to allow escaped strings

See original GitHub issue

I just stumbled upon an issue while using the macro @R_str in combination with variables. As macros execute the input in a different namespace, it is not possible to dynamically access e.g. array fields in a loop.

Problematic behavior:

@R_str "myArray[item.id]" led to this error: item not defined

Workaround / proposed fix:

I added another macro with an escaped string, which solved the problem for me:

macro R_str_esc(s)
  :(Symbol($(esc(s))))
end

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10

github_iconTop GitHub Comments

2reactions
hhaenselcommented, Mar 11, 2022

Escaping for R_str is not a good idea. The reason is that Vue supports javascript expressions to be evaluated for its fields. Imagine you would have an array of tooltips tips = ["Hello", "World"] and you wanted to link the first array element to your tooltip. In html code this would read

<q-tooltip v-model="tip[0]"></q-tooltip>"

With StippleUI this translates to

tooltip(fieldname = R"tips[0]")

This would not be possible to write with escaped syntax. Also note the zero-based indexing in javascript.

For your use case I’d rather go for converting it to Symbol explicitly:

tooltip(fieldname = Symbol(myArray[item.id])
0reactions
mdotendcommented, Mar 14, 2022

Thank you, that works as intended without the macro!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Escaping strings - ETL
Escaping a string means to reduce ambiguity in quotes (and other characters) used in that string. For instance, when you're defining a string,...
Read more >
why using javascript escape character of quotation in string ...
The trick is that the string is escaped and upon assignment immediately unescaped (by executing a JavaScript expression) on the fly, i.e. .value ......
Read more >
How to Escape Special Characters of a Python String ... - Finxter
Rate this post. The backslash escape character '\' is a special Python string character that is usually followed by an alphabetic character.
Read more >
String resources | Android Developers
When a string contains characters that have special usage in XML, you must escape the characters according to the standard XML/HTML escaping ......
Read more >
Escape Sequences - Salesforce Help
You can use the backslash character (\) to escape characters in column names and string values in a predicate expression. You can use...
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