Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/_docs/user-guide/eldritchv2.md
Original file line number Diff line number Diff line change
Expand Up @@ -1965,7 +1965,6 @@ It supports:
- `args` (`List<str>`): List of arguments.
- `disown` (`Option<bool>`): If `True`, runs in background/detached.
- `env_vars` (`Option<Dict<str, str>>`): Environment variables to set.
- `input` (`Option<String>`): String to pass to process stdin

**Returns**
- `Dict`: Output containing `stdout`, `stderr`, and `status` (exit code).
Expand Down
27 changes: 27 additions & 0 deletions implants/lib/eldritchv2/eldritch-core/src/interpreter/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,33 @@ fn evaluate_index(
),
}
}
Value::String(s) => {
let idx_int = match idx_val {
Value::Int(i) => i,
_ => {
return interp.error(
EldritchErrorKind::TypeError,
"string indices must be integers",
index.span,
);
}
};
let chars: Vec<char> = s.chars().collect();
let len = chars.len() as i64;
let true_idx = if idx_int < 0 {
len + idx_int
} else {
idx_int
};
if true_idx < 0 || true_idx as usize >= chars.len() {
return interp.error(
EldritchErrorKind::IndexError,
"String index out of range",
span,
);
}
Ok(Value::String(chars[true_idx as usize].to_string()))
}
_ => interp.error(
EldritchErrorKind::TypeError,
&format!("'{}' object is not subscriptable", get_type_name(&obj_val)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,7 @@ pub fn get_dir_attributes(value: &Value) -> Vec<String> {
"union".to_string(),
"update".to_string(),
],
Value::String(_) => vec![
"endswith".to_string(),
"find".to_string(),
"format".to_string(),
"join".to_string(),
"lower".to_string(),
"replace".to_string(),
"split".to_string(),
"startswith".to_string(),
"strip".to_string(),
"upper".to_string(),
],
Value::String(s) => super::methods::get_native_methods(&Value::String(s.clone())),
Value::Foreign(f) => f.method_names(),
_ => Vec::new(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ fn test_eval_index_out_of_bounds() {
assert::fail("(1,)[-2]", "Tuple index out of range");

// String
// Eldritch doesn't seem to support string indexing in eval.rs yet?
// Wait, evaluate_index only handles List, Tuple, Dictionary.
// Let's verify this failure.
assert::fail("'abc'[0]", "'string' object is not subscriptable");
assert::fail("'abc'[10]", "String index out of range");
}

#[test]
Expand Down