Loading lib/generators.nix +13 −11 Original line number Diff line number Diff line Loading @@ -297,17 +297,19 @@ rec { else if isFloat v then "~${toString v}" else if isString v then let # Separate a string into its lines newlineSplits = filter (v: ! isList v) (builtins.split "\n" v); # For a '' string terminated by a \n, which happens when the closing '' is on a new line multilineResult = "''" + introSpace + concatStringsSep introSpace (lib.init newlineSplits) + outroSpace + "''"; # For a '' string not terminated by a \n, which happens when the closing '' is not on a new line multilineResult' = "''" + introSpace + concatStringsSep introSpace newlineSplits + "''"; # For single lines, replace all newlines with their escaped representation singlelineResult = "\"" + libStr.escape [ "\"" ] (concatStringsSep "\\n" newlineSplits) + "\""; in if multiline && length newlineSplits > 1 then if lib.last newlineSplits == "" then multilineResult else multilineResult' else singlelineResult lines = filter (v: ! isList v) (builtins.split "\n" v); escapeSingleline = libStr.escape [ "\\" "\"" "\${" ]; escapeMultiline = libStr.replaceStrings [ "\${" "''" ] [ "''\${" "'''" ]; singlelineResult = "\"" + concatStringsSep "\\n" (map escapeSingleline lines) + "\""; multilineResult = let escapedLines = map escapeMultiline lines; # The last line gets a special treatment: if it's empty, '' is on its own line at the "outer" # indentation level. Otherwise, '' is appended to the last line. lastLine = lib.last escapedLines; in "''" + introSpace + concatStringsSep introSpace (lib.init escapedLines) + (if lastLine == "" then outroSpace else introSpace + lastLine) + "''"; in if multiline && length lines > 1 then multilineResult else singlelineResult else if true == v then "true" else if false == v then "false" else if null == v then "null" Loading lib/tests/misc.nix +8 −8 Original line number Diff line number Diff line Loading @@ -727,7 +727,7 @@ runTests { float = 0.1337; bool = true; emptystring = ""; string = ''fno"rd''; string = "fn\${o}\"r\\d"; newlinestring = "\n"; path = /. + "/foo"; null_ = null; Loading @@ -735,7 +735,7 @@ runTests { functionArgs = { arg ? 4, foo }: arg; list = [ 3 4 function [ false ] ]; emptylist = []; attrs = { foo = null; "foo bar" = "baz"; }; attrs = { foo = null; "foo b/ar" = "baz"; }; emptyattrs = {}; drv = deriv; }; Loading @@ -744,7 +744,7 @@ runTests { float = "~0.133700"; bool = "true"; emptystring = ''""''; string = ''"fno\"rd"''; string = ''"fn\''${o}\"r\\d"''; newlinestring = "\"\\n\""; path = "/foo"; null_ = "null"; Loading @@ -752,7 +752,7 @@ runTests { functionArgs = "<function, args: {arg?, foo}>"; list = "[ 3 4 ${function} [ false ] ]"; emptylist = "[ ]"; attrs = "{ foo = null; \"foo bar\" = \"baz\"; }"; attrs = "{ foo = null; \"foo b/ar\" = \"baz\"; }"; emptyattrs = "{ }"; drv = "<derivation ${deriv.name}>"; }; Loading Loading @@ -799,8 +799,8 @@ runTests { newlinestring = "\n"; multilinestring = '' hello there test ''${there} te'''st ''; multilinestring' = '' hello Loading @@ -827,8 +827,8 @@ runTests { multilinestring = '' ''' hello there test '''''${there} te''''st '''''; multilinestring' = '' ''' Loading Loading
lib/generators.nix +13 −11 Original line number Diff line number Diff line Loading @@ -297,17 +297,19 @@ rec { else if isFloat v then "~${toString v}" else if isString v then let # Separate a string into its lines newlineSplits = filter (v: ! isList v) (builtins.split "\n" v); # For a '' string terminated by a \n, which happens when the closing '' is on a new line multilineResult = "''" + introSpace + concatStringsSep introSpace (lib.init newlineSplits) + outroSpace + "''"; # For a '' string not terminated by a \n, which happens when the closing '' is not on a new line multilineResult' = "''" + introSpace + concatStringsSep introSpace newlineSplits + "''"; # For single lines, replace all newlines with their escaped representation singlelineResult = "\"" + libStr.escape [ "\"" ] (concatStringsSep "\\n" newlineSplits) + "\""; in if multiline && length newlineSplits > 1 then if lib.last newlineSplits == "" then multilineResult else multilineResult' else singlelineResult lines = filter (v: ! isList v) (builtins.split "\n" v); escapeSingleline = libStr.escape [ "\\" "\"" "\${" ]; escapeMultiline = libStr.replaceStrings [ "\${" "''" ] [ "''\${" "'''" ]; singlelineResult = "\"" + concatStringsSep "\\n" (map escapeSingleline lines) + "\""; multilineResult = let escapedLines = map escapeMultiline lines; # The last line gets a special treatment: if it's empty, '' is on its own line at the "outer" # indentation level. Otherwise, '' is appended to the last line. lastLine = lib.last escapedLines; in "''" + introSpace + concatStringsSep introSpace (lib.init escapedLines) + (if lastLine == "" then outroSpace else introSpace + lastLine) + "''"; in if multiline && length lines > 1 then multilineResult else singlelineResult else if true == v then "true" else if false == v then "false" else if null == v then "null" Loading
lib/tests/misc.nix +8 −8 Original line number Diff line number Diff line Loading @@ -727,7 +727,7 @@ runTests { float = 0.1337; bool = true; emptystring = ""; string = ''fno"rd''; string = "fn\${o}\"r\\d"; newlinestring = "\n"; path = /. + "/foo"; null_ = null; Loading @@ -735,7 +735,7 @@ runTests { functionArgs = { arg ? 4, foo }: arg; list = [ 3 4 function [ false ] ]; emptylist = []; attrs = { foo = null; "foo bar" = "baz"; }; attrs = { foo = null; "foo b/ar" = "baz"; }; emptyattrs = {}; drv = deriv; }; Loading @@ -744,7 +744,7 @@ runTests { float = "~0.133700"; bool = "true"; emptystring = ''""''; string = ''"fno\"rd"''; string = ''"fn\''${o}\"r\\d"''; newlinestring = "\"\\n\""; path = "/foo"; null_ = "null"; Loading @@ -752,7 +752,7 @@ runTests { functionArgs = "<function, args: {arg?, foo}>"; list = "[ 3 4 ${function} [ false ] ]"; emptylist = "[ ]"; attrs = "{ foo = null; \"foo bar\" = \"baz\"; }"; attrs = "{ foo = null; \"foo b/ar\" = \"baz\"; }"; emptyattrs = "{ }"; drv = "<derivation ${deriv.name}>"; }; Loading Loading @@ -799,8 +799,8 @@ runTests { newlinestring = "\n"; multilinestring = '' hello there test ''${there} te'''st ''; multilinestring' = '' hello Loading @@ -827,8 +827,8 @@ runTests { multilinestring = '' ''' hello there test '''''${there} te''''st '''''; multilinestring' = '' ''' Loading