]> granicus.if.org Git - jq/commitdiff
Fix #718
authorNicolas Williams <nico@cryptonector.com>
Fri, 6 Mar 2015 06:18:45 +0000 (00:18 -0600)
committerNicolas Williams <nico@cryptonector.com>
Fri, 6 Mar 2015 06:18:45 +0000 (00:18 -0600)
builtin.c

index 05d4c86c718e5669b9e39cb858bc1bba2f9178ec..a6557b81827b9a9cc39bd30f61e8f24786904dbc 100644 (file)
--- a/builtin.c
+++ b/builtin.c
@@ -80,6 +80,8 @@ static jv f_negate(jq_state *jq, jv input) {
 }
 
 static jv f_startswith(jq_state *jq, jv a, jv b) {
+  if (jv_get_kind(a) != JV_KIND_STRING || jv_get_kind(b) != JV_KIND_STRING)
+    return jv_invalid_with_msg(jv_string("startswith() requires string inputs"));
   int alen = jv_string_length_bytes(jv_copy(a));
   int blen = jv_string_length_bytes(jv_copy(b));
   jv ret;
@@ -94,6 +96,8 @@ static jv f_startswith(jq_state *jq, jv a, jv b) {
 }
 
 static jv f_endswith(jq_state *jq, jv a, jv b) {
+  if (jv_get_kind(a) != JV_KIND_STRING || jv_get_kind(b) != JV_KIND_STRING)
+    return jv_invalid_with_msg(jv_string("endswith() requires string inputs"));
   const char *astr = jv_string_value(a);
   const char *bstr = jv_string_value(b);
   size_t alen = jv_string_length_bytes(jv_copy(a));