From c279369a7a9e373bb4b88feff0a05f56f3c0fa3b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Sat, 17 Jun 2023 11:55:12 +0200 Subject: [PATCH] ; * src/treesit.c (treesit_query_string_string): fix last change Escape the backslash character itself. --- src/treesit.c | 6 ++++-- test/src/treesit-tests.el | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/treesit.c b/src/treesit.c index 680e510b74d..87aa1eeb377 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -2312,7 +2312,8 @@ treesit_query_string_string (Lisp_Object str) for (ptrdiff_t i = 0; i < nbytes; i++) { unsigned char c = SREF (str, i); - escapes += (c == '\0' || c == '\n' || c == '\r' || c == '\t' || c == '"'); + escapes += (c == '\0' || c == '\n' || c == '\r' || c == '\t' + || c == '"' || c == '\\'); } ptrdiff_t nchars = SCHARS (str); ptrdiff_t extra = escapes + 2; /* backslashes + double quotes */ @@ -2331,7 +2332,8 @@ treesit_query_string_string (Lisp_Object str) case '\n': *d++ = '\\'; *d++ = 'n'; break; case '\r': *d++ = '\\'; *d++ = 'r'; break; case '\t': *d++ = '\\'; *d++ = 't'; break; - case '"': *d++ = '\\'; *d++ = '"'; break; + case '"': + case '\\': *d++ = '\\'; *d++ = c; break; default: *d++ = c; break; } } diff --git a/test/src/treesit-tests.el b/test/src/treesit-tests.el index 6e7d0fc48d2..34540b463cd 100644 --- a/test/src/treesit-tests.el +++ b/test/src/treesit-tests.el @@ -465,8 +465,8 @@ BODY is the test body." ;; Test string conversion in `treesit-pattern-expand'. (should (equal - (treesit-pattern-expand "a\nb\rc\td\0e\"f\1g") - "\"a\\nb\\rc\\td\\0e\\\"f\1g\""))))) + (treesit-pattern-expand "a\nb\rc\td\0e\"f\1g\\h\fi") + "\"a\\nb\\rc\\td\\0e\\\"f\1g\\\\h\fi\""))))) ;;; Narrow -- 2.39.2