about summary refs log tree commit diff
path: root/lib/strings.nix
AgeCommit message (Collapse)AuthorFilesLines
2017-03-19lib.readPathsFromFile: simplify, /cc #24036Orivej Desh1-3/+1
This part isn't needed after 36de745e1b7.
2017-03-19readPathsFromFile: fixup after #23851Vladimír Čunát1-1/+1
The final newline would produce an empty string; let's filter all empty lines as well.
2017-03-15libs: make splitString also split last separator (#23851)Léo Gaspard1-1/+1
* libs: make splitString also split last separator * libs: add tests for splitStrings
2016-08-13getVersion: first try drv.version before parsing drv.nameDomen Kožar1-1/+6
2016-08-12fix documentation typo in lib/strings.nix (#17684)Данило Глинський (Danylo Hlynskyi)1-1/+1
2016-08-10hasSuffix: human readable inputsDomen Kožar1-5/+5
2016-08-01lib: add fileContents functionEric Sagnes1-0/+10
2016-06-20lib: Make escapeShellArg more robustaszlig1-8/+7
Quoting various characters that the shell *may* interpret specially is a very fragile thing to do. I've used something more robust all over the place in various Nix expression I've written just because I didn't trust escapeShellArg. Here is a proof of concept showing that I was indeed right in distrusting escapeShellArg: with import <nixpkgs> {}; let payload = runCommand "payload" {} '' # \x00 is not allowed for Nix strings, so let's begin at 1 for i in $(seq 1 255); do echo -en "\\x$(printf %02x $i)" done > "$out" ''; escapers = with lib; { current = escapeShellArg; better = arg: let backslashEscapes = stringToCharacters "\"\\ ';$`()|<>\r\t*[]&!~#"; search = backslashEscapes ++ [ "\n" ]; replace = map (c: "\\${c}") backslashEscapes ++ [ "'\n'" ]; in replaceStrings search replace (toString arg); best = arg: "'${replaceStrings ["'"] ["'\\''"] (toString arg)}'"; }; testWith = escaper: let escaped = escaper (builtins.readFile payload); in runCommand "test" {} '' if ! r="$(bash -c ${escapers.best "echo -nE ${escaped}"} 2> /dev/null)" then echo bash eval error > "$out" exit 0 fi if echo -n "$r" | cmp -s "${payload}"; then echo success > "$out" else echo failed > "$out" fi ''; in runCommand "results" {} '' echo "Test results:" ${lib.concatStrings (lib.mapAttrsToList (name: impl: '' echo " ${name}: $(< "${testWith impl}")" '') escapers)} exit 1 '' The resulting output is the following: Test results: best: success better: success current: bash eval error I did the "better" implementation just to illustrate that the method of quoting only "harmful" characters results in madness in terms of implementation and performance. Signed-off-by: aszlig <aszlig@redmoonstudios.org> Cc: @edolstra, @zimbatm
2016-06-19Merge pull request #16180 from zimbatm/shell-escapingzimbatm1-1/+10
Escape all shell arguments uniformly
2016-06-17Remove unecessary branching on old nix versionszimbatm1-5/+1
All these builtins are available since 1.10 or earlier (1.10 being the lib/minver.nix)
2016-06-12Escape all shell arguments uniformlyzimbatm1-1/+10
2016-05-19lib: revert my bogus comment fixNikolay Amiantov1-1/+1
See https://github.com/NixOS/nixpkgs/commit/5445e521b6524587489c6968cc27347977b9b7b8#commitcomment-17531945
2016-05-19firefox: restore gstreamer support for older firefox releasesNikolay Amiantov1-1/+1
2016-04-25make*Path: implement via makeSearchPathOutputNikolay Amiantov1-7/+3
2016-04-25makeSearchPathOutputs: refactor to makeSearchPathOutputNikolay Amiantov1-5/+4
2016-04-13makeSearchPath (and derivatives): check outputUnspecifiedNikolay Amiantov1-4/+4
2016-04-13makePerlPath: try to guess outputsNikolay Amiantov1-1/+2
2016-04-13makeSearchPathOutputs: init functionNikolay Amiantov1-0/+10
2016-04-13makeBinPath: guess outputsNikolay Amiantov1-1/+2
2016-04-10Merge branch 'master' into closure-sizeVladimír Čunát1-1/+1
Comparison to master evaluations on Hydra: - 1255515 for nixos - 1255502 for nixpkgs
2016-04-01Stronger warning against usage of splitStringEelco Dolstra1-1/+1
2016-04-01Merge branch 'master' into closure-sizeVladimír Čunát1-62/+274
Beware that stdenv doesn't build. It seems something more will be needed than just resolution of merge conflicts.
2016-03-10lib/strings: document all the functionszimbatm1-62/+274
2016-01-19Merge branch 'staging' into closure-sizeVladimír Čunát1-3/+7
2016-01-05lib.getVersion: extend the function to cope with strings as well as derivationsPeter Simons1-3/+7
2015-12-31Merge branch 'master' into closure-sizeVladimír Čunát1-0/+15
TODO: there was more significant refactoring of qtbase and plasma 5.5 on master, and I'm deferring pointing to correct outputs to later.
2015-12-16lib/strings: add readPathsFromFileThomas Tuegel1-0/+15
2015-12-11Merge branch 'master' into closure-sizeLuca Bruno1-0/+4
2015-12-10add makeBinPath function for abstracting away pkg/bin:pkg2/bin..Domen Kožar1-0/+4
2015-11-25Merge remote-tracking branch 'origin/master' into closure-sizeLuca Bruno1-0/+8
2015-11-25lib/strings: add a `toInt` helper (close #11242)Christian Zagrodnick1-0/+8
While the function itself is pretty easy, it's not straitforward to find a way to convert string to int with nix.
2015-10-03Merge commit staging+systemd into closure-sizeVladimír Čunát1-50/+54
Many non-conflict problems weren't (fully) resolved in this commit yet.
2015-08-07Allow options with type "package" to be store pathsEelco Dolstra1-0/+5
For example, this allows writing nix.package = /nix/store/786mlvhd17xvcp2r4jmmay6jj4wj6b7f-nix-1.10pre4206_896428c; Also, document types.package in the manual.
2015-07-24intersperse: Fix quadratic performanceEelco Dolstra1-5/+4
2015-07-24Remove eqStringsEelco Dolstra1-22/+14
It's no longer needed. Also clean up some comments.
2015-07-24Use replaceStrings primopEelco Dolstra1-18/+18
2015-07-24Use concatStringSep primopEelco Dolstra1-3/+7
2015-07-23Rename misc.nix -> deprecated.nixEelco Dolstra1-0/+2
2015-07-23Use foldl' instead of fold in some placesEelco Dolstra1-1/+1
2015-07-13Issue 8152 - Reduce number of attribute set created by replaceChars.Nicolas B. Pierron1-4/+6
2015-05-05systemPackages, makeLibraryPath: try to guess outputsVladimír Čunát1-1/+3
2015-03-08Add 'fixedWidthString' and 'fixedWidthNumber' formatting functionsNikita Mikhailov1-0/+11
2014-10-05lib: Use arithmetic operators rather than builtins.add etc.Eelco Dolstra1-8/+8
2014-08-25Added concatMapStringsSep and concatImapStringsSepIgor Pashev1-0/+3
Example: configure rewrite rules for Mediawiki RewriteEngine On RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d ${concatMapStringsSep "\n" (u: "RewriteCond %{REQUEST_URI} !^${u.urlPath}") serverInfo.serverConfig.servedDirs} RewriteRule ${if config.enableUploads
2014-06-11lib: Do not take string context into accountKirill Elagin1-7/+12
Close #2883.
2014-05-13lib/strings: add hasPrefix and simplify hasSuffixVladimír Čunát1-6/+8
It was discussed as a part of #2570.
2014-05-13lib/strings: simplify removePrefix readabilityVladimír Čunát1-2/+2
It was discussed as a part of #2570.
2014-05-09fetchFromGitHub: Use .tar.gz instead of .zipEelco Dolstra1-0/+10
Also clean up the name attribute of fetchzip derivations a bit.
2013-11-12Add some primops to libEelco Dolstra1-1/+2
2013-10-10Move pkgs/lib/ to lib/Eelco Dolstra1-0/+190