From e4b82af38711126bb2a531451a28b062937a5a81 Mon Sep 17 00:00:00 2001 From: Guillaume Maudoux Date: Fri, 24 Jun 2016 15:30:19 +0200 Subject: [PATCH] Improve error message on trailing path slashes --- src/libexpr/lexer.l | 16 ++++++++++++---- tests/lang/eval-fail-path-slash.nix | 6 ++++++ 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 tests/lang/eval-fail-path-slash.nix diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l index 3ac7ce723..56d8456c0 100644 --- a/src/libexpr/lexer.l +++ b/src/libexpr/lexer.l @@ -87,8 +87,8 @@ static Expr * unescapeStr(SymbolTable & symbols, const char * s) ID [a-zA-Z\_][a-zA-Z0-9\_\'\-]* INT [0-9]+ FLOAT (([1-9][0-9]*\.[0-9]*)|(0?\.[0-9]+))([Ee][+-]?[0-9]+)? -PATH [a-zA-Z0-9\.\_\-\+]*(\/[a-zA-Z0-9\.\_\-\+]+)+ -HPATH \~(\/[a-zA-Z0-9\.\_\-\+]+)+ +PATH [a-zA-Z0-9\.\_\-\+]*(\/[a-zA-Z0-9\.\_\-\+]+)+\/? +HPATH \~(\/[a-zA-Z0-9\.\_\-\+]+)+\/? SPATH \<[a-zA-Z0-9\.\_\-\+]+(\/[a-zA-Z0-9\.\_\-\+]+)*\> URI [a-zA-Z][a-zA-Z0-9\+\-\.]*\:[a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~\*\']+ @@ -182,8 +182,16 @@ or { return OR_KW; } { -{PATH} { yylval->path = strdup(yytext); return PATH; } -{HPATH} { yylval->path = strdup(yytext); return HPATH; } +{PATH} { if (yytext[yyleng-1] == '/') + throw ParseError(format("Invalid path '%1%'; trailing slashes are not allowed in paths") % yytext); + yylval->path = strdup(yytext); + return PATH; + } +{HPATH} { if (yytext[yyleng-1] == '/') + throw ParseError(format("Invalid path '%1%'; trailing slashes are not allowed in paths") % yytext); + yylval->path = strdup(yytext); + return HPATH; + } {SPATH} { yylval->path = strdup(yytext); return SPATH; } {URI} { yylval->uri = strdup(yytext); return URI; } diff --git a/tests/lang/eval-fail-path-slash.nix b/tests/lang/eval-fail-path-slash.nix new file mode 100644 index 000000000..530105b32 --- /dev/null +++ b/tests/lang/eval-fail-path-slash.nix @@ -0,0 +1,6 @@ +# Trailing slashes in paths are not allowed. +# This restriction could be lifted sometime, +# for example if we make '/' a path concatenation operator. +# See https://github.com/NixOS/nix/issues/1138 +# and http://lists.science.uu.nl/pipermail/nix-dev/2016-June/020829.html +/nix/store/