aboutsummaryrefslogtreecommitdiffhomepage
path: root/parse_util.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-03-18 14:14:32 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-03-20 21:32:02 -0700
commite5ef45e4c04b6126ea74c4010b2d8fe1c0b06cca (patch)
treed200c10a700c9cfae10d170a600acfda8508086a /parse_util.cpp
parente780637cf42bc8d26e0e963f5ff84b11007459c5 (diff)
Rewrite parser_t::test_args and parser_t::eval_args to use new parser
Diffstat (limited to 'parse_util.cpp')
-rw-r--r--parse_util.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/parse_util.cpp b/parse_util.cpp
index e7c1873d..dda4f6a7 100644
--- a/parse_util.cpp
+++ b/parse_util.cpp
@@ -1135,12 +1135,19 @@ parser_test_error_bits_t parse_util_detect_errors_in_argument(const parse_node_t
tmp.push_back(INTERNAL_SEPARATOR);
tmp.append(paran_end+1);
- parse_error_list_t errors;
- err |= parse_util_detect_errors(subst, &errors);
+ parse_error_list_t subst_errors;
+ err |= parse_util_detect_errors(subst, &subst_errors);
+
+ /* Our command substitution produced error offsets relative to its source. Tweak the offsets of the errors in the command substitution to account for both its offset within the string, and the offset of the node */
+ size_t error_offset = (paran_begin + 1 - arg_cpy) + node.source_start;
+ for (size_t i=0; i < subst_errors.size(); i++)
+ {
+ subst_errors.at(i).source_start += error_offset;
+ }
+
if (out_errors != NULL)
{
- /* Todo: have to tweak the offsets of the errors in the command substitution */
- out_errors->insert(out_errors->end(), errors.begin(), errors.end());
+ out_errors->insert(out_errors->end(), subst_errors.begin(), subst_errors.end());
}
free(arg_cpy);
@@ -1239,6 +1246,7 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src, pars
// Verify 'or' and 'and' not used inside pipelines
// Verify pipes via parser_is_pipe_forbidden
// Verify return only within a function
+ // Verify no variable expansions
if (! errored)
{
@@ -1286,6 +1294,13 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src, pars
errored = append_syntax_error(&parse_errors, node, ILLEGAL_CMD_ERR_MSG, command.c_str());
}
+ // Check that it doesn't contain a variable
+ // Note this check is clumsy (it doesn't allow for escaping) but it matches what we do in parse_execution
+ if (command.find(L'$') != wcstring::npos)
+ {
+ errored = append_syntax_error(&parse_errors, node, ILLEGAL_CMD_ERR_MSG, command.c_str());
+ }
+
// Check that pipes are sound
if (! errored && parser_is_pipe_forbidden(command) && is_in_pipeline)
{