ssh_tests.rs 832 B

123456789101112131415161718192021222324252627282930
  1. use super::shq;
  2. #[test]
  3. fn shq_quotes_plain_word() {
  4. assert_eq!(shq("--kv-cache-dtype"), "'--kv-cache-dtype'");
  5. }
  6. #[test]
  7. fn shq_escapes_interior_quote() {
  8. assert_eq!(shq("it's"), r#"'it'\''s'"#);
  9. }
  10. #[test]
  11. fn shq_passes_through_already_quoted_token() {
  12. // an operator pre-quoted value (e.g. JSON arg) is a single-quoted shell
  13. // word already -> pass through, do not double-quote it.
  14. assert_eq!(shq("'{\"cuda\":\"x\"}'"), "'{\"cuda\":\"x\"}'");
  15. }
  16. #[test]
  17. fn shq_quotes_injectable_value_whole() {
  18. // metachars keep the whole value as ONE quoted argument.
  19. assert_eq!(shq("x; touch /tmp/pwned"), "'x; touch /tmp/pwned'");
  20. }
  21. #[test]
  22. fn shq_quotes_unbalanced_leading_quote() {
  23. // a single leading quote is not a complete token -> still escaped.
  24. assert_eq!(shq("'untuple"), r#"''\''untuple'"#);
  25. }