diff --git a/t/custom_gcode.t b/t/custom_gcode.t
index 62bd7993c..2cb9a44b8 100644
--- a/t/custom_gcode.t
+++ b/t/custom_gcode.t
@@ -1,4 +1,4 @@
-use Test::More tests => 39;
+use Test::More tests => 40;
 use strict;
 use warnings;
 
@@ -55,6 +55,9 @@ use Slic3r::Test;
     is $parser->process('{temperature[foo]}'),
         $config->temperature->[0],
         "array reference";
+    is $parser->process("test [ temperature_ [foo] ] \n hu"),
+        "test " . $config->temperature->[0] . " \n hu",
+        "whitespaces and newlines are maintained";
 }
 
 {
diff --git a/xs/src/libslic3r/PlaceholderParser.cpp b/xs/src/libslic3r/PlaceholderParser.cpp
index ace63a4b5..655913d90 100644
--- a/xs/src/libslic3r/PlaceholderParser.cpp
+++ b/xs/src/libslic3r/PlaceholderParser.cpp
@@ -641,7 +641,7 @@ namespace client
 
             // Free-form text up to a first brace, including spaces and newlines.
             // The free-form text will be inserted into the processed text without a modification.
-            text = raw[no_skip[+(char_ - '[' - '{')]];
+            text = no_skip[raw[+(char_ - '[' - '{')]];
             text.name("text");
 
             // New style of macro expansion.