- vector lines = frrstr_split_vec(buf, "\n");
-
- frrstr_filter_vec(lines, &vty->include);
- vector_compact(lines);
-
- /*
- * Consider the string "foo\n". If the regex is an empty string
- * and the line ended with a newline, then the vector will look
- * like:
- *
- * [0]: 'foo'
- * [1]: ''
- *
- * If the regex isn't empty, the vector will look like:
- *
- * [0]: 'foo'
- *
- * In this case we'd like to preserve the newline, so we add
- * the empty string [1] as in the first example.
- */
- if (buf[strlen(buf) - 1] == '\n' && vector_active(lines) > 0
- && strlen(vector_slot(lines, vector_active(lines) - 1)))
- vector_set(lines, XSTRDUP(MTYPE_TMP, ""));
+ vector lines = frrstr_split_vec(p, "\n");
+
+ /* Place first value in the cache */
+ char *firstline = vector_slot(lines, 0);
+ buffer_put(vty->lbuf, (uint8_t *) firstline, strlen(firstline));
+
+ /* If our split returned more than one entry, time to filter */
+ if (vector_active(lines) > 1) {
+ /*
+ * returned string is MTYPE_TMP so it matches the MTYPE
+ * of everything else in the vector
+ */
+ char *bstr = buffer_getstr(vty->lbuf);
+ buffer_reset(vty->lbuf);
+ XFREE(MTYPE_TMP, lines->index[0]);
+ vector_set_index(lines, 0, bstr);
+ frrstr_filter_vec(lines, &vty->include);
+ vector_compact(lines);
+ /*
+ * Consider the string "foo\n". If the regex is an empty string
+ * and the line ended with a newline, then the vector will look
+ * like:
+ *
+ * [0]: 'foo'
+ * [1]: ''
+ *
+ * If the regex isn't empty, the vector will look like:
+ *
+ * [0]: 'foo'
+ *
+ * In this case we'd like to preserve the newline, so we add
+ * the empty string [1] as in the first example.
+ */
+ if (p[strlen(p) - 1] == '\n' && vector_active(lines) > 0
+ && strlen(vector_slot(lines, vector_active(lines) - 1)))
+ vector_set(lines, XSTRDUP(MTYPE_TMP, ""));
+
+ filtered = frrstr_join_vec(lines, "\n");
+ }
+ else {
+ filtered = NULL;
+ }