Open EnderShadow opened 9 months ago
Pinging @elastic/es-core-infra (Team:Core/Infra)
There's nothing about newlines that requires painless to restrict them. The escapes you mentioned are specifically to allow strings to be encoded within the JSON string a painless script is defined in. But JSON does not allow newline characters within strings. This isn't something painless can really workaround, any actual newline character whether prefixed by a \
or not, will break parsing.
@EnderShadow Can you provide an example for this use-case?
Yes, I have a watcher which checks the status of ECE to send alerts to my team. To make it easier for us to read, I use newlines to separate sections of the message. Currently I have actual newlines in the string.
String message = "";
if(allocator_messages.size() > 0) {
message = "The following allocators are unhealthy: " + allocator_messages.join('
');
}
if(instance_messages.size() > 0) {
if(message != "") {
message == "
";
}
message += "The following nodes are unhealthy:
" + instance_messages.join('
');
}
It would be much clearer and nicer to write it as
String message = "";
if(allocator_messages.size() > 0) {
message = "The following allocators are unhealthy:\n" + allocator_messages.join('\n');
}
if(instance_messages.size() > 0) {
if(message != "") {
message == "\n\n";
}
message += "The following nodes are unhealthy:\n" + instance_messages.join('\n');
}
Description
Painless only supports escaping backslashes, double quotes, and single quotes. Newlines and tabs should also be supported to allow for more readable painless scripts which use those escapes when transforming and formatting text.