4 ms·
Took me a bit to figure out that it's using Ruby code like this to fool the surrounding CI scripts. "b/#{puts 'test';}" That happens to run the code within
by tyingq 6y ago
Took me a bit to figure out that it's using Ruby code like this to fool the surrounding CI scripts.
"b/#{puts 'test';}"
That happens to run the code within the braces, despite it all being enclosed in double quotes and preceded with a #. Can a Ruby person explain what's happening here? I understand it's working as designed.
Edit: Ah, okay, so the interpolation is #{code here;} everything else is a just a string in quotes. Interesting that they use the # character to denote interpolation.
- iudqnolq 6y agoIt's string interpolation where you can provide an expression, not just a variable. > String interpolation is common in many programming languages which make heavy use of string representations of data, such as Apache Groovy, Kotlin, Perl, PHP, Python, Ruby, Scala, Swift, Tcl and most Unix shells. Two modes of literal expression are usually offered: one with interpolation enabled, the other without (termed raw string). Placeholders are usually represented by a bare or a named sigil (typically $ or %), e.g. $placeholder or %123. Expansion of the string usually occurs at run time. https://en.wikipedia.org/wiki/String_interpolation#%3A%7E%3Atext%3DString_interpolation_is_common_in%2CTcl_and_most_Unix_shells.?wprov=sfla1 https://en.wikipedia.org/wiki/String_interpolation#%3A%7E%3A...
- KMnO4 6y agoString interpolation. It can be used for good but it’s possible to exploit if the user picks the string. Many languages have exactly the same feature: Python: f”Price: {get_price()}” JavaScript: `Price: ${get_price()}` Notice how both Python and JS require more than just double quotes; you have to explicitly opt in with f-strings or template literals.
- tyingq 6y agoIt was Ruby's use of the # character for interpolation that was throwing me off. Apparently you can skip the braces too, if the # precedes some types of variables.
- burlesona 6y agoRuby is also opt-in in the sense that single quoted strings do not support interpolation, and while the language doesn’t care if you use single or double quotes, most linters will enforce single quotes as the default.