Fix assert fail on invalid import path (fix #899)
This commit is contained in:
1 parent
5479d7f2dc
commit
7b5c6a9224
3 files changed
+1103
-1044
No files matched your search
@@ -112,7 +112,7 @@ struct lexer_param;
|
||||
|
||||
|
||||
%type <blk> Exp Term MkDict MkDictPair ExpD ElseBody QQString String
|
||||
%type <blk> FuncDef FuncDefs Import Imports ImportWhat Param Params
|
||||
%type <blk> FuncDef FuncDefs Import Imports ImportWhat ImportFrom Param Params
|
||||
%type <blk> Arg Args Module Pattern ArrayPats ObjPats ObjPat
|
||||
%type <literal> Keyword
|
||||
%{
|
||||
@@ -186,6 +186,16 @@ static block constant_fold(block a, block b, int op) {
|
||||
if (!block_is_single(a) || !block_is_const(a) ||
|
||||
!block_is_single(b) || !block_is_const(b))
|
||||
return gen_noop();
|
||||
if (op == '+') {
|
||||
if (block_const_kind(a) == JV_KIND_NULL) {
|
||||
block_free(a);
|
||||
return b;
|
||||
}
|
||||
if (block_const_kind(b) == JV_KIND_NULL) {
|
||||
block_free(b);
|
||||
return a;
|
||||
}
|
||||
}
|
||||
if (block_const_kind(a) != block_const_kind(b))
|
||||
return gen_noop();
|
||||
|
||||
@@ -491,7 +501,7 @@ ImportWhat Exp ';' {
|
||||
}
|
||||
|
||||
ImportWhat:
|
||||
"import" String "as" '$' IDENT {
|
||||
"import" ImportFrom "as" '$' IDENT {
|
||||
jv v = block_const($2);
|
||||
// XXX Make gen_import take only blocks and the int is_data so we
|
||||
// don't have to free so much stuff here
|
||||
@@ -500,20 +510,31 @@ ImportWhat:
|
||||
jv_free($5);
|
||||
jv_free(v);
|
||||
} |
|
||||
"import" String "as" IDENT {
|
||||
"import" ImportFrom "as" IDENT {
|
||||
jv v = block_const($2);
|
||||
$$ = gen_import(jv_string_value(v), jv_string_value($4), 0);
|
||||
block_free($2);
|
||||
jv_free($4);
|
||||
jv_free(v);
|
||||
} |
|
||||
"include" String {
|
||||
"include" ImportFrom {
|
||||
jv v = block_const($2);
|
||||
$$ = gen_import(jv_string_value(v), NULL, 0);
|
||||
block_free($2);
|
||||
jv_free(v);
|
||||
}
|
||||
|
||||
ImportFrom:
|
||||
String {
|
||||
if (!block_is_const($1)) {
|
||||
FAIL(@$, "Import path must be constant");
|
||||
$$ = gen_const(jv_string(""));
|
||||
block_free($1);
|
||||
} else {
|
||||
$$ = $1;
|
||||
}
|
||||
}
|
||||
|
||||
FuncDef:
|
||||
"def" IDENT ':' Exp ';' {
|
||||
$$ = gen_function(jv_string_value($2), gen_noop(), $4);
|
||||
|
||||
@@ -1189,6 +1189,14 @@ jq: error: Module metadata must be constant at <top-level>, line 1:
|
||||
include "a" []; 0
|
||||
jq: error: Module metadata must be an object at <top-level>, line 1:
|
||||
|
||||
%%FAIL
|
||||
include "\ "; 0
|
||||
jq: error: Invalid escape at line 1, column 4 (while parsing '"\ "') at <top-level>, line 1:
|
||||
|
||||
%%FAIL
|
||||
include "\(a)"; 0
|
||||
jq: error: Import path must be constant at <top-level>, line 1:
|
||||
|
||||
modulemeta
|
||||
"c"
|
||||
{"whatever":null,"deps":[{"as":"foo","is_data":false,"relpath":"a"},{"search":"./","as":"d","is_data":false,"relpath":"d"},{"search":"./","as":"d2","is_data":false,"relpath":"d"},{"search":"./../lib/jq","as":"e","is_data":false,"relpath":"e"},{"search":"./../lib/jq","as":"f","is_data":false,"relpath":"f"},{"as":"d","is_data":true,"relpath":"data"}]}
|
||||
|
||||
Reference in new issue
Block a user