Skip to content

Commit

Permalink
treewide: Escape backslash in strings properly
Browse files Browse the repository at this point in the history
"\." is apparently the same as "." wheras the correct one is "\\."
  • Loading branch information
dezgeg committed Sep 13, 2017
1 parent 62711f4 commit 0c368ef
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions nixos/modules/services/misc/geoip-updater.nix
Expand Up @@ -238,15 +238,15 @@ in

assertions = [
{ assertion = (builtins.filter
(x: builtins.match ".*\.(gz|xz)$" x == null) cfg.databases) == [];
(x: builtins.match ".*\\.(gz|xz)$" x == null) cfg.databases) == [];
message = ''
services.geoip-updater.databases supports only .gz and .xz databases.
Current value:
${toString cfg.databases}
Offending element(s):
${toString (builtins.filter (x: builtins.match ".*\.(gz|xz)$" x == null) cfg.databases)};
${toString (builtins.filter (x: builtins.match ".*\\.(gz|xz)$" x == null) cfg.databases)};
'';
}
];
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/idris-modules/default.nix
Expand Up @@ -26,7 +26,7 @@
};

files = builtins.filter (n: n != "default") (pkgs.lib.mapAttrsToList (name: type: let
m = builtins.match "(.*)\.nix" name;
m = builtins.match "(.*)\\.nix" name;
in if m == null then "default" else builtins.head m) (builtins.readDir ./.));
in (builtins.listToAttrs (map (name: {
inherit name;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/top-level/impure.nix
Expand Up @@ -50,7 +50,7 @@ in
# it's a directory, so the set of overlays from the directory, ordered lexicographically
let content = readDir path; in
map (n: import (path + ("/" + n)))
(builtins.filter (n: builtins.match ".*\.nix" n != null || pathExists (path + ("/" + n + "/default.nix")))
(builtins.filter (n: builtins.match ".*\\.nix" n != null || pathExists (path + ("/" + n + "/default.nix")))
(attrNames content))
else
# it's a file, so the result is the contents of the file itself
Expand Down

6 comments on commit 0c368ef

@bjornfor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this? Is it a bug in Nix?

@dezgeg
Copy link
Contributor Author

@dezgeg dezgeg commented on 0c368ef Sep 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is debatable. Other programming languages don't seem to agree either:

$ irb
irb(main):001:0> "\."
=> "."

$ python3 
>>> "\."
'\\.'

$ ghci
Prelude> "\."

<interactive>:1:3: error:
    lexical error in string/character literal at character '.'

@bjornfor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC @edolstra.

@edolstra
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a bug. The backslash escapes any character, so \. is equivalent to ..

@7c6f434c
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And that is why I prefer to escape dots in regexps as [.]

@dezgeg
Copy link
Contributor Author

@dezgeg dezgeg commented on 0c368ef Sep 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it does harm future extensibility, since (say) adding a new backslash escape for "\e" risks changing behaviour of old code (with the Haskell/C behaviour of throwing an error being the ideal).

Please sign in to comment.